Mac OS是Unix系统的分支,有着强大的命令行功能。很多事情在命令行下处理会事半功倍,所以我就iOS程序员可能会用到的功能讲述一下。
终端设置
Mac的终端有一个很关键的配置,就是“使用 Option 键作为 Meta 键”。勾上这个选项之后,就可以使用Emacs的编辑命令了。
Snip20150413_5我发现有些人的终端没有设置“平滑文本”,导致终端上的文字很难看。赶紧把这个选项勾上吧。
Snip20150413_7常用的几个快捷键如下。
- control+a,跳到命令行开始位置;control+e,跳到命令行结尾位置。
- option+f,向前跳一个word;option+b,向后跳一个word。
- option+d,向后删除一个word;option+delete,向前删除一个word。
- control+_,撤销之前一次编辑操作。
- control+k,删除到行尾;control+u,删除到行首。
终端颜色高亮也不错,看起来感觉会更有感觉。比如ls可以看到目录会是蓝色的,普通文件是白色的,可执行程序会是绿色的。
Snip20150413_4具体设置可以参考:让Mac OS X的终端多姿多彩。
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"参数都没有。具体安装和配置的方法在让Mac OS X的终端多姿多彩这篇文章里面也有。
Snip20150419_87Xcode图形化操作挺好用的,不过知道一些命令行的操作会更佳。在下面这个地方看到Xcode编译的详细过程。
Snip20150413_3如果在编译的时候遇到链接错误,在命令行下检查一下就非常有必要了。下面这个命令就是链接生成来往二进制程序的,可以拷贝到终端里面运行。如果链接出错误了,可以仔细检查一下这个命令。
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:]
- otool,查看查看可执行程序的信息。比如查看可执行程序依赖的动态库信息。
[~]$ otool -L /Users/henshao/Library/Developer/Xcode/DerivedData/CloudConsoleApp-gszptqenpqtwraajgpawanvtjtny/Build/Products/Debug-iphonesimulator/CloudConsoleApp.app/CloudConsoleApp
/Users/henshao/Library/Developer/Xcode/DerivedData/CloudConsoleApp-gszptqenpqtwraajgpawanvtjtny/Build/Products/Debug-iphonesimulator/CloudConsoleApp.app/CloudConsoleApp:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 237.2.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 55.1.0)
/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 216.7.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
@rpath/AFNetworking.framework/AFNetworking (compatibility version 1.0.0, current version 1.0.0)
@rpath/ALYUIKit.framework/ALYUIKit (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
/System/Library/Frameworks/AVKit.framework/AVKit (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Accounts.framework/Accounts (compatibility version 1.0.0, current version 0.0.0)
/System/Library/Frameworks/AddressBook.framework/AddressBook (compatibility version 1.0.0, current version 30.0.0)
/System/Library/Frameworks/AddressBookUI.framework/AddressBookUI (compatibility version 1.0.0, current version 33.0.0)
- lsof,观察描述符的信息。比如观察系统中https的连接情况。
[~]$ lsof -i:443
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
AliLang 910 henshao 9u IPv4 0x3db3574b61c3c44b 0t0 TCP 10.65.155.189:55448->42.156.140.98:https (ESTABLISHED)
AliLang 910 henshao 11u IPv4 0x3db3574b61c3c44b 0t0 TCP 10.65.155.189:55448->42.156.140.98:https (ESTABLISHED)
AliLang 910 henshao 26u IPv4 0x3db3574b61a3225b 0t0 TCP 10.65.155.189:52167->140.205.224.47:https (ESTABLISHED)
AliLang 910 henshao 31u IPv4 0x3db3574b61a3225b 0t0 TCP 10.65.155.189:52167->140.205.224.47:https (ESTABLISHED)
node 33986 henshao 32u IPv4 0x3db3574b602f525b 0t0 TCP 30.9.158.49:53822->ec2-54-235-138-91.compute-1.amazonaws.com:https (ESTABLISHED)
nwjs 77209 henshao 129u IPv4 0x3db3574b6360d06b 0t0 TCP 10.65.155.189:54516->140.205.32.75:https (ESTABLISHED)
^C
[~]$ ps aux | grep 910
henshao 910 0.0 0.2 2728464 20204 ?? S 1 716 10:55.29 /Applications/AliLang.app/Contents/MacOS/AliLang
- Swift符号demangle
$ xcrun swift-demangle __TFFC15CloudConsoleApp31ALYDomainNewOwnerViewController7confirmFPs9AnyObject_T_U_FGSQGVs10DictionaryCSo8NSObjectPS1____T_
_TFFC15CloudConsoleApp31ALYDomainNewOwnerViewController7confirmFPs9AnyObject_T_U_FGSQGVs10DictionaryCSo8NSObjectPS1____T_ ---> CloudConsoleApp.ALYDomainNewOwnerViewController.(confirm (Swift.AnyObject) -> ()).(closure #1)
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: git@mirror.git.alibaba-inc.com: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: git@mirror.git.alibaba-inc.com:SwiftyJSON/SwiftyJSON.git
- Versions: 2.3.2, 2.3.1, 2.3.0, 2.2.1, 2.2.0, 2.1.3 [master repo]
为了方便执行pod update --verbose
,可以设置一个别名,比如pu
,这样可以快得飞起。
$ echo "alias pu='pod update --verbose'" >> ~/.bash_profile && . ~/.bash_profile
$ pu
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推送信息,感觉蛮不错的。详细介绍请看:使用Houston给iOS APP推送信息。
网友评论