Mac OS是Unix系統的分支,有著強大的命令行功能。很多事情在命令行下處理會事半功倍,所以我就iOS程序員可能會用到的功能講述一下。
終端設置
Mac的終端有一個很關鍵的配置,就是“使用 Option 鍵作為 Meta 鍵”。勾上這個選項之後,就可以使用Emacs的編輯命令了。
我發現有些人的終端沒有設置“平滑文本”,導致終端上的文字很難看。趕緊把這個選項勾上吧。
常用的幾個快捷鍵如下。
control+a,跳到命令行開始位置;control+e,跳到命令行結尾位置。
option+f,向後跳一個word;option+b,向前跳一個word。
option+d,向後刪除一個word;option+delete,向前刪除一個word。
control+_,撤銷之前一次編輯操作。
control+k,刪除到行尾;control+u,刪除到行首。
終端顏色高亮也不錯,看起來感覺會更有感覺。比如ls可以看到目錄會是藍色的,普通文件是白色的,可執行程序會是綠色的。
homebrew
homebrew是一個非常有用包管理工具,通過homebrew可以安裝更多有用的unix工具,比如wget、tree等等。
安裝
目前最好的安裝方式都是下面這樣的,一句命令搞定。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
使用
[~]$ brew install tree ==> Downloading http://mama.indstate.edu/users/ice/tree/src/tree-1.7.0.tgz Already downloaded: /Library/Caches/Homebrew/tree-1.7.0.tgz ==> make prefix=/usr/local/Cellar/tree/1.7.0 MANDIR=/usr/local/Cellar/tree/1.7.0/share/man/man1 CC=clang CFLAGS=-fomit-frame-pointer LD /usr/local/Cellar/tree/1.7.0: 7 files, 128K, built in 2 seconds
tree這個工具看目錄的內容非常直觀好看。
[~/ilaiwang/LWShareTo]$ tree . ├── LWShareTo │ ├── LWShareContent.h │ ├── LWShareContent.m │ ├── LWShareTo-Prefix.pch │ ├── LWShareTo.h │ ├── LWShareTo.m │ ├── LWShareToMacro.h │ ├── LWShareToUtils.h │ ├── LWShareToUtils.m │ ├── ShareModule │ │ ├── LWShareChannelService.h │ │ ├── LWShareChannelService.m │ │ ├── LWShareToBaseClass.h │ │ ├── LWShareToBaseClass.m │ │ ├── LWShareToClipboard.h │ │ ├── LWShareToClipboard.m │ │ ├── LWShareToDouban.h │ │ ├── LWShareToDouban.m │ │ ├── LWShareToInside.h │ │ ├── LWShareToInside.m │ │ ├── LWShareToLWFeed.h │ │ ├── LWShareToLWFeed.m │ │ ├── LWShareToLWSession.h │ │ ├── LWShareToLWSession.m │ │ ├── LWShareToOutside.h │ │ ├── LWShareToOutside.m │ │ ├── LWShareToQQSession.h │ │ ├── LWShareToQQSession.m │ │ ├── LWShareToQQZone.h │ │ ├── LWShareToQQZone.m │ │ ├── LWShareToRenren.h │ │ ├── LWShareToRenren.m │ │ ├── LWShareToSinaWeibo.h │ │ ├── LWShareToSinaWeibo.m │ │ ├── LWShareToTencentWeibo.h │ │ ├── LWShareToTencentWeibo.m │ │ ├── LWShareToWechatSession.h │ │ ├── LWShareToWechatSession.m │ │ ├── LWShareToWechatTimeline.h │ │ └── LWShareToWechatTimeline.m │ ├── WebviewRender.h │ └── WebviewRender.m ├── LWShareTo.xcodeproj │ └── project.pbxproj └── LWShareToTests ├── LWShareToTests-Info.plist ├── LWShareToTests.m └── en.lproj └── InfoPlist.strings 5 directories, 44 files
shell
GNU Coreutils包含了各種GNU好用的工具。根據我的觀察,我發現Mac預裝了Coreutils,只是版本比較低,建議自己安裝一下,否者sort連”-h”參數都沒有。
Xcode圖形化操作挺好用的,不過知道一些命令行的操作會更佳。在下面這個地方看到Xcode編譯的詳細過程。
如果在編譯的時候遇到鏈接錯誤,在命令行下檢查一下就非常有必要了。下面這個命令就是鏈接生成來往二進制程序的,可以拷貝到終端裡面運行。如果鏈接出錯誤了,可以仔細檢查一下這個命令。
Ld /Users/henshao/Library/Developer/Xcode/DerivedData/Laiwang-fxscnxkslrypubbeazdfkveysldy/Build/Products/Debug-iphoneos/Laiwang.app/Laiwang normal arm64 cd /Users/henshao/ilaiwang/LaiwangV3 export IPHONEOS_DEPLOYMENT_TARGET=6.0 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk -L/Users/henshao/Library/Developer/Xcode/DerivedData/Laiwang-fxscnxkslrypubbeazdfkveysldy/Build/Products/Debug-iphoneos -L/Users/henshao/ilaiwang/LaiwangV3/../Pods/LWComponentKits/LWComponentKits/AMAP/liboffset -L/Users/henshao/ilaiwang/LaiwangV3/../Pods/LWXiamiMusic/Output -L/Users/henshao/ilaiwang/LaiwangV3/../Pods/QupaiSDK/libQupaiSDK -L/Users/henshao/ilaiwang/LaiwangV3/../Pods/VoIPSDK/SDK/lib -F/Users/henshao/Library/Developer/Xcode/DerivedData/Laiwang-fxscnxkslrypubbeazdfkveysldy/Build/Products/Debug-iphoneos -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/AMap3DMap -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/AMapSearch -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/DevicePrint -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/TBSecuritySDK -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/SecurityGuardSDK -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/UserTrack -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/PLCrashReporter/iOS\ Framework -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/MtopSDK -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/SpeechRecognizer -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/TBScanLib -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/TBShortURL -F/Users/henshao/ilaiwang/LaiwangV3 -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/TencentOpenApiSDK/64Bit -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/huoyanSDK_laiwang -F/Users/henshao/ilaiwang/LaiwangV3/../Pods/mtopext -F/Users/henshao/ilaiwang/LaiwangV3/Laiwang/LWUIKits/AlipaySDK_2 -F. -FLaiwang -FLaiwangShare -FLaiwangTests -FLaiwang/BaseFrame -FLaiwang/BaseLogic -FLaiwang/Cache -FLaiwang/DataProvider -FLaiwang/DataSource -FLaiwang/DevTools -FLaiwang/H5_Slider_local -FLaiwang/Init -FLaiwang/Integration -FLaiwang/LWSafeMode -FLaiwang/LWUIKits -FLaiwang/PageViews -FLaiwang/SDK -FLaiwang/Sounds -FLaiwang/TestUtility -FLaiwang/UserControls -FLaiwang/Utils -FLaiwangTests/LWServiceTests -FLaiwangTests/Other -FLaiwang/BaseFrame/LWController -FLaiwang/BaseFrame/LWUISDK -FLaiwang/BaseFrame/URLCoordinator -FLaiwang/Cache/LWDataCache -FLaiwang/Cache/LWDB -FLaiwang/Cache/LWDBModel -FLaiwang/H5_Slider_local/app.slide -FLaiwang/Integration/LWService -FLaiwang/Integration/LWServiceTests -FLaiwang/LWUIKits/AlipaySDK_2 -FLaiwang/LWUIKits/LWAlbumPhotoPreview -FLaiwang/LWUIKits/LWCameraCaptureView -FLaiwang/LWUIKits/LWMovieView -FLaiwang/LWUIKits/MMDrawerController -FLaiwang/LWUIKits/TableViewCell -FLaiwang/PageViews/AlbumPage -FLaiwang/PageViews/ChatPage -FLaiwang/PageViews/DiscoveryExPage -FLaiwang/PageViews/EmotionBoxPage -FLaiwang/PageViews/EventPage -FLaiwang/PageViews/FeedPage -FLaiwang/PageViews/FriendPage -FLaiwang/PageViews/FriendRadarPage -FLaiwang/PageViews/IntroducePage -FLaiwang/PageViews/KnockPage -FLaiwang/PageViews/LoginPage -FLaiwang/PageViews/MinePage -FLaiwang/PageViews/MorePage -FLaiwang/PageViews/MoviePage -FLaiwang/PageViews/MusicPage -FLaiwang/PageViews/NearByPage -FLaiwang/PageViews/NewGuidePage -FLaiwang/PageViews/NotificationPage -FLaiwang/PageViews/OAuthPage -FLaiwang/PageViews/PhotoEditorPage -FLaiwang/PageViews/PhotoFilterPage -FLaiwang/PageViews/PostPage -FLaiwang/PageViews/PubAccountPage -FLaiwang/PageViews/SearchPage -FLaiwang/PageViews/SharedPage -FLaiwang/PageViews/ShareMsgPage -FLaiwang/PageViews/XiamiPage -FLaiwang/SDK/EggShell -FLaiwang/SDK/InternalSDK -FLaiwang/SDK/LWFileUploadManager -FLaiwang/SDK/LWHostService -FLaiwang/SDK/LWShareTo -FLaiwang/SDK/SSOApiEngine -FLaiwang/SDK/ViewModels -FLaiwang/SDK/VOIP -FLaiwang/Sounds/asr -FLaiwang/Sounds/radar -FLaiwang/TestUtility/APNSTest -FLaiwang/TestUtility/TimeCounter -FLaiwang/UserControls/BigImageControl -FLaiwang/UserControls/LWAsrBoard -FLaiwang/UserControls/LWAvatarView -FLaiwang/UserControls/LWBrowserViewController -FLaiwang/UserControls/LWCloudAudioPlayerBox -FLaiwang/UserControls/LWCustomUI -FLaiwang/UserControls/LWEasyInputView -FLaiwang/UserControls/LWEmotionView -FLaiwang/UserControls/LWLocationDirectionView -FLaiwang/UserControls/LWLocationDisplayView -FLaiwang/UserControls/LWNativeBridgeWebView -FLaiwang/UserControls/LWObjSelectControl -FLaiwang/UserControls/LWPicker -FLaiwang/UserControls/LWPictureViewer -FLaiwang/UserControls/LWProgressView -FLaiwang/UserControls/LWRichTextContentView -FLaiwang/UserControls/LWScrollTabBar -FLaiwang/UserControls/LWSettingsItem -FLaiwang/UserControls/LWTextZoomView -FLaiwang/UserControls/LWToastView -FLaiwang/UserControls/LWVoiceWidget -FLaiwang/UserControls/LWVoipView -FLaiwang/UserControls/LWWebImageView -FLaiwang/UserControls/LWWebViewController -FLaiwang/UserControls/LWXiamiBar -FLaiwang/UserControls/QBImagePicker -FLaiwang/Utils/ABContact -FLaiwang/Utils/ALAssetsLibrary-CustomPhotoAlbum -FLaiwang/Utils/ASR -FLaiwang/Utils/AWActionSheet -FLaiwang/Utils/Category -FLaiwang/Utils/CompatibleUtil -FLaiwang/Utils/GDataXMLNode -FLaiwang/Utils/Huoyan -FLaiwang/Utils/ImageDownloader -FLaiwang/Utils/LWAppURLNavigator -FLaiwang/Utils/LWBizSearch -FLaiwang/Utils/LWDataStore -FLaiwang/Utils/LWFav -FLaiwang/Utils/LWLocalPageURLRouter -FLaiwang/Utils/LWLocationManager -FLaiwang/Utils/LWMusic -FLaiwang/Utils/LWPushDispatcher -FLaiwang/Utils/LWStatistics -FLaiwang/Utils/NSStringAdditions -FLaiwang/Utils/OffLineSendUtil -FLaiwang/Utils/QupaiSDK -FLaiwang/Utils/SDWebImage -FLaiwang/Utils/SoundEffect -FLaiwang/Utils/UIImageAdditions -FLaiwang/Utils/UIImagePickerControllerAdditions -FLaiwang/Utils/UT -FLaiwang/BaseFrame/LWController/LWTabBarController -FLaiwang/H5_Slider_local/app.slide/css -FLaiwang/H5_Slider_local/app.slide/images -FLaiwang/H5_Slider_local/app.slide/js -FLaiwang/Integration/LWService/ios -FLaiwang/Integration/LWServiceTests/LWPackTests -FLaiwang/Integration/LWServiceTests/LWServiceTests -FLaiwang/LWUIKits/AlipaySDK_2/AlipaySDK.bundle -FLaiwang/PageViews/AlbumPage/Cells -FLaiwang/PageViews/AlbumPage/UserControls -FLaiwang/PageViews/ChatPage/BubbleDay -FLaiwang/PageViews/ChatPage/Cells -FLaiwang/PageViews/ChatPage/MessageSender -FLaiwang/PageViews/ChatPage/MomoChat -FLaiwang/PageViews/ChatPage/UserControls -FLaiwang/PageViews/EventPage/EventCommon -FLaiwang/PageViews/EventPage/EventCreate -FLaiwang/PageViews/EventPage/EventDeprecated -FLaiwang/PageViews/EventPage/EventList -FLaiwang/PageViews/EventPage/EventLottery -FLaiwang/PageViews/EventPage/EventMain -FLaiwang/PageViews/EventPage/EventNotification -FLaiwang/PageViews/EventPage/EventPostDetail -FLaiwang/PageViews/EventPage/EventRecent -FLaiwang/PageViews/EventPage/EventRecommend -FLaiwang/PageViews/EventPage/EventSearch -FLaiwang/PageViews/EventPage/EventSetting -FLaiwang/PageViews/EventPage/EventWall -FLaiwang/PageViews/EventPage/EventZan -FLaiwang/PageViews/EventPage/PubEventRecent -FLaiwang/PageViews/FeedPage/Cells -FLaiwang/PageViews/FeedPage/UserControls -FLaiwang/PageViews/FriendPage/Cells -FLaiwang/PageViews/FriendPage/UserControls -FLaiwang/PageViews/FriendRadarPage/PSCollectionView -FLaiwang/PageViews/FriendRadarPage/PulsingHalo -FLaiwang/PageViews/FriendRadarPage/RNBlurModalView -FLaiwang/PageViews/KnockPage/Answer -FLaiwang/PageViews/KnockPage/Browse -FLaiwang/PageViews/KnockPage/KnockList -FLaiwang/PageViews/KnockPage/SetQuestion -FLaiwang/PageViews/KnockPage/Setting -FLaiwang/PageViews/KnockPage/Statistic -FLaiwang/PageViews/KnockPage/UserControls -FLaiwang/PageViews/KnockPage/VoiceCard -FLaiwang/PageViews/MinePage/UserControls -FLaiwang/PageViews/MorePage/Cells -FLaiwang/PageViews/NotificationPage/Cells -FLaiwang/PageViews/NotificationPage/UserControls -FLaiwang/PageViews/PhotoEditorPage/DataProvider -FLaiwang/PageViews/PhotoEditorPage/DBModel -FLaiwang/PageViews/PhotoEditorPage/UserControls -FLaiwang/PageViews/PostPage/cells -FLaiwang/PageViews/PostPage/UserControls -FLaiwang/PageViews/PubAccountPage/Cells -FLaiwang/PageViews/PubAccountPage/PubToolBar -FLaiwang/PageViews/PubAccountPage/UserControls -FLaiwang/PageViews/SearchPage/SearchCell -FLaiwang/PageViews/SearchPage/SearchCellModel -FLaiwang/PageViews/SearchPage/SearchMsgListPage -FLaiwang/PageViews/SharedPage/Cells -FLaiwang/PageViews/SharedPage/UserControls -FLaiwang/PageViews/ShareMsgPage/UserControls -FLaiwang/SDK/InternalSDK/InternalModel -FLaiwang/SDK/InternalSDK/InternalService -FLaiwang/SDK/LWFileUploadManager/LWProgressObserverCenter -FLaiwang/SDK/LWHostService/BizTasks -FLaiwang/SDK/LWHostService/Utils -FLaiwang/SDK/LWShareTo/ShareModule -FLaiwang/SDK/LWShareTo/ShareRes -FLaiwang/SDK/LWShareTo/ShareService -FLaiwang/SDK/ViewModels/Friends -FLaiwang/SDK/ViewModels/Knock -FLaiwang/SDK/ViewModels/Others -FLaiwang/UserControls/LWProgressView/DACircularProgress -FLaiwang/UserControls/QBImagePicker/LWQBImagePicker+External -FLaiwang/Utils/LWFav/core -FLaiwang/Utils/LWFav/Images -FLaiwang/Utils/LWFav/libs -FLaiwang/Utils/LWFav/UI -FLaiwang/Utils/LWMusic/XiamiSDK -FLaiwang/Utils/NSStringAdditions/NSString_HTML -FLaiwang/Utils/UT/SinaWeibo.bundle -FLaiwang/Integration/LWService/ios/lwservice -FLaiwang/PageViews/EventPage/EventCommon/AttachmentView -FLaiwang/PageViews/EventPage/EventCommon/Comment -FLaiwang/PageViews/EventPage/EventSearch/LWBubbleView -FLaiwang/PageViews/EventPage/EventSearch/LWEventSearchCell -FLaiwang/PageViews/EventPage/EventWall/EventSignIn -FLaiwang/PageViews/KnockPage/Browse/KnockFlipTransition -FLaiwang/PageViews/KnockPage/Browse/LWKnockLocationManager -FLaiwang/Utils/LWFav/libs/CDClient -FLaiwang/Utils/LWFav/libs/file_hash -FLaiwang/Utils/LWFav/libs/GHKit -FLaiwang/Utils/LWFav/libs/PopoverView -FLaiwang/Utils/LWFav/UI/views -FLaiwang/Utils/LWMusic/XiamiSDK/Classes -FLaiwang/Utils/UT/SinaWeibo.bundle/images -FLaiwang/Integration/LWService/ios/lwservice/LaiwangRPC -FLaiwang/Utils/LWMusic/XiamiSDK/Classes/Player -F/Users/henshao/ilaiwang/LaiwangV3/Laiwang -filelist /Users/henshao/Library/Developer/Xcode/DerivedData/Laiwang-fxscnxkslrypubbeazdfkveysldy/Build/Intermediates/Laiwang.build/Debug-iphoneos/Laiwang.build/Objects-normal/arm64/Laiwang.LinkFileList -dead_strip -ObjC -lCNG -lG711 -lG729 -lPods-AMap3DMap -lPods-AMapSearch -lPods-CocoaAsyncSocket -lPods-DevicePrint -lPods-FLEX -lPods-HTTPDNS -lPods-JDStatusBarNotification -lPods-JSONKit -lPods-LWComponentKits -lPods-LWGPUImage -lPods-LWGraffiti -lPods-LWHttpDNSInterceptor -lPods-LWImageAssets -lPods-LWImageFilter -lPods-LWJSONKit -lPods-LWNetworkKit -lPods-LWPlugin -lPods-LWShareKit -lPods-LWXiamiMusic -lPods-MJRefresh -lPods-MtopSDK -lPods-NJKWebViewProgress -lPods-OpenUDID -lPods-PLCrashReporter -lPods-PSTCollectionView -lPods-QupaiSDK -lPods-Reachability -lPods-RegexKitLite -lPods-SDWebImage -lPods-SecurityGuardSDK -lPods-SpeechRecognizer -lPods-TBMstore -lPods-TBScanLib -lPods-TBSecuritySDK -lPods-TBShortURL -lPods-THLabel -lPods-TencentOpenApiSDK -lPods-UserTrack -lPods-VoIPSDK -lPods-ZipArchive -lPods-crossplay -lPods-huoyanSDK_laiwang -lPods-libextobjc -lPods-libwebp -lPods-lwsdk -lPods-mtopext -lQupaiSDK -laudio_coding_module -laudio_conference_mixer -laudio_decoder_interface -laudio_device -laudio_encoder_interface -laudio_processing -lavcodec -lavformat -lavutil -lbitrate_controller -lc++ -lcommon_audio -lcommon_video -lfield_trial_default -liSAC -liSACFix -licucore -lmedia_file -lmetrics_default -lneteq -loffset -lopus -lpaced_sender -lrbe_components -lred -lremote_bitrate_estimator -lrtc_base_approved -lrtc_sound -lrtp_rtcp -lsqlite3 -lsrtp -lstdc++ -lstdc++.6.0.9 -lswscale -lsystem_wrappers -ltbconf -lvideo_coding_utility -lvideo_engine_core -lvideo_processing -lvideo_render_module -lvideo_render_module_impl -lvideo_render_module_internal_impl -lvoice_engine -lwebrtc -lwebrtc_common -lwebrtc_h264 -lwebrtc_i420 -lwebrtc_opus -lwebrtc_utility -lwebrtc_video_coding -lx264 -lxiamiMusic -lxml2 -lyuv -lyuv_neon -lz -framework AMapSearchKit -framework AVFoundation -framework AudioToolbox -framework CFNetwork -framework CoreFoundation -framework CoreGraphics -framework CoreLocation -framework CoreMedia -framework CoreTelephony -framework CoreText -framework CrashReporter -framework DevicePrint -framework Foundation -framework GLKit -framework ImageIO -framework MAMapKit -framework MobileCoreServices -framework MtopSDK -framework OpenGLES -framework QuartzCore -framework Security -framework SecurityGuardSDK -framework SpeechRecognizer -framework SystemConfiguration -framework TBScanLib -framework TBSecuritySDK -framework TBShortURLResolve -framework TencentOpenAPI -framework UIKit -framework UT -framework huoyan -framework mtopext -weak_framework AdSupport -lstdc++ -ObjC -fobjc-arc -fobjc-arc -fobjc-link-runtime -miphoneos-version-min=6.0 -framework LocalAuthentication -framework GameKit -framework AddressBookUI -framework Accelerate -lstdc++.6.0.9 -lxml2 -framework MediaPlayer -framework GLKit -lz -framework SystemConfiguration -framework CoreTelephony -framework Security -framework MessageUI -framework AudioToolbox -framework MobileCoreServices -framework ImageIO -framework QuartzCore -lsqlite3 -lz.1.2.5 -lresolv -liconv -framework AlipaySDK -licucore -framework OpenGLES -framework MapKit -framework CFNetwork -framework AddressBook -framework AssetsLibrary -framework AVFoundation -framework CoreAudio -framework CoreData -framework ShareSDK -framework CoreLocation -framework CoreMedia -framework CoreVideo -framework CoreGraphics -framework UIKit -framework Foundation -lPods -Xlinker -dependency_info -Xlinker /Users/henshao/Library/Developer/Xcode/DerivedData/Laiwang-fxscnxkslrypubbeazdfkveysldy/Build/Intermediates/Laiwang.build/Debug-iphoneos/Laiwang.build/Objects-normal/arm64/Laiwang_dependency_info.dat -o /Users/henshao/Library/Developer/Xcode/DerivedData/Laiwang-fxscnxkslrypubbeazdfkveysldy/Build/Products/Debug-iphoneos/Laiwang.app/Laiwang
常用的工具如下。
find,查找文件。比如我想分析一下來往源代碼各個部分的文件數量。可以發現業務裡面文件數量最多的三個業務分別是扎堆、敲門和聊天。
[~/ilaiwang/LaiwangV3/Laiwang/PageViews]$ find . -maxdepth 1 -type d -print0 | xargs -0 -I {} sh -c 'echo $(find {} -type f | wc -l) {}' | sort -nr 914 . 167 ./EventPage 92 ./ChatPage 91 ./KnockPage 88 ./FriendPage 86 ./PubAccountPage 54 ./FeedPage 47 ./SharedPage 44 ./PostPage 29 ./SearchPage 29 ./PhotoEditorPage 29 ./MorePage 28 ./NearByPage 26 ./FriendRadarPage 15 ./LoginPage 14 ./MinePage 14 ./AlbumPage 12 ./PhotoFilterPage 10 ./EmotionBoxPage 9 ./ShareMsgPage 8 ./XiamiPage 8 ./NotificationPage 4 ./IntroducePage 2 ./OAuthPage 2 ./NewGuidePage 2 ./MusicPage 2 ./MoviePage 2 ./DiscoveryExPage
grep,搜索文本。結合正則表達式,分析日志什麼的,非常之強大。grep有幾個有用的選項,分別是“-r”遞歸搜索目錄;“-i”,忽略大小寫;“-c”,統計符合搜索條件的文本的行數;“–color”,高亮搜索結果。
du,統計目錄大小。比如我想知道來往圖片資源的情況。可以看出圖片資源一共有8.2MB,其中共享的圖片占到2.1MB,其次是聊天的圖片占了1.4MB。
[~/iOS_release/lwimageassets]$ du -sh LWImageAssets 8.2M LWImageAssets [~/iOS_release/lwimageassets/LWImageAssets]$ du -sh * | sort -hr 2.1M shared_img 1.4M chat_img 636K event_img 528K icon_default 524K feed_img 472K post_img 464K knock_img 392K radar_img 284K profile_img 264K friend_img 236K pub_account_map_img 140K editor_img 132K yifa_img 132K emotion_img 84K neighbour_img 80K lwuikits_img 76K discovery_img 72K graffiti_img 72K asr_img 60K login_img 52K video_guide_img 44K qr_img 40K more_img 36K share_msg_img 32K my_img 20K slide_img 16K animal_img 12K xiamibar_img 4.0K search_img 4.0K movie_img
file,用於查看文件信息。
$ file libxiamiMusic.a libxiamiMusic.a: Mach-O universal binary with 4 architectures libxiamiMusic.a (for architecture armv7): current ar archive random library libxiamiMusic.a (for architecture i386): current ar archive random library libxiamiMusic.a (for architecture x86_64): current ar archive random library libxiamiMusic.a (for architecture arm64): current ar archive random library $ file Laiwang Laiwang: Mach-O 64-bit executable
strings,查看文件中的文本信息。
$ strings Laiwang | head -n 10 kSearchTextKey kSearchedPersonKey invalid_token user_in_black_list user_blocked expired_token invalid_grant refreshed_token client_id client_secret
nm,查看可執行程序裡面的符號信息。
$ nm Laiwang | head -n 10 00000001001425e4 t +[ABContact addressWithStreet:withCity:withState:withZip:withCountry:withCode:] 0000000100142484 t +[ABContact arrayForProperty:inRecord:] 0000000100146438 t +[ABContact contactWithData:] 000000010014591c t +[ABContact contactWithDictionary:] 000000010014191c t +[ABContact contactWithRecord:] 0000000100141984 t +[ABContact contactWithRecordID:] 0000000100141b70 t +[ABContact contact] 000000010014252c t +[ABContact dictionaryWithValue:andLabel:] 0000000100141c50 t +[ABContact localizedPropertyName:] 00000001001424e8 t +[ABContact objectForProperty:inRecord:]
vim
做簡單的文本編輯和分析,vim是非常方便的。最簡單有用的配置如下。在HOME目錄下創建.vimrc隱藏文件,把下面的內容拷貝進去即可。
syntax on #支持語法高亮,看源代碼文件會很舒服。 set hls #使用 / 查找內容的時候,會高亮字符串。 set ic #搜索的時候忽略大小寫
CocoaPods
CocoaPods的源都安裝在”~/.cocoapods/repos”目錄下,有時候找不到pod、版本有問題、或者想確定一下pod的信息,都可以來這個地方翻一翻。
[~/.cocoapods/repos]$ ls TBMainClientSpecs/ alibaba/ master/ [~/.cocoapods/repos]$ ls TBMainClientSpecs/ AMPSDK/ TBCalendar/ TBLoginCenter/ TBScanCode/ TBWeiTao/ AccsSDK/ TBCalendarService/ TBLoginService/ TBScanCodeService/ TBWeiTaoService/ [~]$ pod search swiftyjson -> AISwiftyJSON (1.0.6) AISwiftyJSON makes it easy to deal with JSON data in Swift . pod 'AISwiftyJSON', '~> 1.0.6' - Homepage: https://github.com/asiainfomobile/AISwiftyJSON - Source: [email protected]:asiainfomobile/AISwiftyJSON.git - Versions: 1.0.6, 1.0.3 [master repo] -> SwiftyJSON (2.3.2) SwiftyJSON makes it easy to deal with JSON data in Swift pod 'SwiftyJSON', '~> 2.3.2' - Homepage: https://github.com/SwiftyJSON/SwiftyJSON - Source: [email protected]:SwiftyJSON/SwiftyJSON.git - Versions: 2.3.2, 2.3.1, 2.3.0, 2.2.1, 2.2.0, 2.1.3 [master repo]
sqlite
Mac自帶了sqlite命令行工具。小工具用起來很快很方便。所以簡單介紹一下怎麼使用這個工具。其實”.help”講得很詳細啦。
[~/Downloads]$ sqlite3 laiwang.sqlite3 SQLite version 3.8.5 2014-08-15 22:37:57 Enter ".help" for usage hints. sqlite> .tables lw_messages lw_session_event_post lw_offline_post2 lw_sessions sqlite> .schema lw_sessions CREATE TABLE lw_sessions (primaryKey INTEGER primary key autoincrement, sessionId TEXT, userId TEXT, title TEXT, icon TEXT, content TEXT, sourceType TEXT, data BLOB, actionType TEXT, actionContent TEXT, senderId TEXT, settings BLOB, unreadCount INTEGER, pushEnnabled INTEGER, lastModify TEXT, ancientStampInDB TEXT, recentStampInDB TEXT, sortIndex INTEGER, background TEXT, members BLOB); CREATE UNIQUE INDEX idx_sessions_SidUidSt ON lw_sessions(sessionId, userId, sourceType); CREATE INDEX idx_sessions_UidStSiLm ON lw_sessions(userId, sourceType, sortIndex, lastModify); sqlite> select * from lw_sessions limit 1; 1|2651304|2921438|新浪新聞|http://i01.lw.aliimg.com/tfs/T1vldnFFXbXXbKnNzJLAIWANGtebus_73957a0c_180_180.60x60.jpg||pubmessage|||{"type":""}|||0|0|1429026489000|||0||
Python SimpleHTTPServer
SimpleHTTPServer模塊絕對是Python最有用的一個模塊(另外一個可能是json)。一個命令就能啟動一個Web服務器,做演示或者mock接口,不要太方便了。
[~]$ python -m SimpleHTTPServer 9876 Serving HTTP on 0.0.0.0 port 9876 ...
nomad houston
nomad houston這個工具支持在命令行下給APP推送信息,感覺蠻不錯的。
以上就是寫給iOS程序員的命令行使用秘籍,認為不錯的朋友收藏起來吧!