必备命令行集合_艾孜尔江撰


Graphical user interfaces are super friendly to computer users. They were introduced in reaction to the perceived steep learning curve of command-line interfaces (CLIs).

However, they often require more resources, are less powerful and hard to automate via scripting.

As a computer expert, we want to be more efficient and do our jobs better. We know that command words may not be easily discoverable or mnemonic, so we try to list some common tasks that you might be tempted to do in GUI.

1|0copy a file

STOP DRAG AND DROPPING A FILE, OR CMD/CTRL + C, CMD/CTRL + V A FILE 👎

Copy readme.txt to the documents directory

$ cp readme.txt documents/

2|0duplicate a file

STOP RIGHT CLICKING AND DUPLICATE A FILE 👎

$ cp readme.txt readme.bak.txt

More advanced:

$ cp readme{,.bak}.txt # Note: learn how the {} works with touch foo{1,2,3}.txt and see what happens.

3|0copy a directory

STOP DRAG AND DROPPING A DIRECTORY, OR CMD/CTRL + C, CMD/CTRL + V A DIRECTORY 👎

Copy myMusic directory to the myMedia directory

$ cp -a myMusic myMedia/ # or $ cp -a myMusic/ myMedia/myMusic/

4|0duplicate a directory

STOP RIGHT CLICKING AND DUPLICATE A DIRECTORY 👎

$ cp -a myMusic/ myMedia/ # or if `myMedia` folder doesn't exist $ cp -a myMusic myMedia/

5|0move a file

STOP DRAG AND DROPPING A FILE, OR CMD/CTRL + X, CMD/CTRL + V A FILE 👎

$ mv readme.txt documents/

Always use a trailing slash when moving files, for this reason.

5|1rename a file

STOP RIGHT CLICKING AND RENAME A FILE 👎

$ mv readme.txt README.md

6|0move a directory

STOP DRAG AND DROPPING A DIRECTORY, OR CMD/CTRL + X, CMD/CTRL + V A DIRECTORY 👎

$ mv myMedia myMusic/ # or $ mv myMedia/ myMusic/myMedia

7|0rename a directory

STOP RIGHT CLICKING AND RENAME A DIRECTORY 👎

$ mv myMedia/ myMusic/

8|0merge directories

STOP DRAG AND DROPPING TO MERGE DIRECTORIES 👎

$ rsync -a /images/ /images2/ # note: may over-write files with the same name, so be careful!

9|0create a new file

STOP RIGHT CLICKING AND CREATE A NEW FILE 👎

$ touch 'new file' # updates the file's access and modification timestamp if it already exists # or $ > 'new file' # note: erases the content if it already exists

10|0create a new directory

STOP RIGHT CLICKING AND CREATE A NEW DIRECTORY 👎

$ mkdir 'untitled folder' # or $ mkdir -p 'path/may/not/exist/untitled\ folder'

11|0show file/directory size

STOP RIGHT CLICKING AND SHOW FILE/directory INFO 👎

$ du -sh node_modules/

12|0show file/directory info

STOP RIGHT CLICKING AND SHOW FILE/DIRECTORY INFO 👎

$ stat -x readme.md # on macOS $ stat readme.md # on Linux

13|0open a file with the default program

STOP DOUBLE CLICKING ON A FILE 👎

$ xdg-open file # on Linux $ open file # on MacOS

14|0zip a directory

STOP RIGHT CLICKING AND COMPRESS DIRECTORY 👎

$ zip -r archive_name.zip folder_to_compress

15|0unzip a directory

STOP RIGHT CLICKING AND UNCOMPRESS DIRECTORY 👎

$ unzip archive_name.zip

16|0peek files in a zip file

STOP USING WinRAR 👎

$ zipinfo archive_name.zip # or $ unzip -l archive_name.zip

16|1remove a file

STOP RIGHT CLICKING AND DELETE A FILE PERMANENTLY 👎

$ rm my_useless_file

IMPORTANT: The rm command deletes my_useless_file permanently, which is equivalent to move my_useless_file to Recycle Bin and hit Empty Recycle Bin.

17|0remove a directory

STOP RIGHT CLICKING AND DELETE A DIRECTORY PERMANENTLY 👎

$ rm -r my_useless_folder

18|0list directory contents

STOP OPENING YOUR FINDER OR FILE EXPLORER 👎

$ ls my_folder # Simple $ ls -la my_folder # -l: show in list format. -a: show all files, including hidden. -la combines those options. $ ls -alrth my_folder # -r: reverse output. -t: sort by time (modified). -h: output human-readable sizes.

19|0tree view a directory and its subdirectories

STOP OPENING YOUR FINDER OR FILE EXPLORER 👎

$ tree # on Linux $ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' # on MacOS # Note: install homebrew (https://brew.sh) to be able to use (some) Linux utilities such as tree. # brew install tree

20|0find a stale file

STOP USING YOUR FILE EXPLORER TO FIND A FILE 👎

Find all files modified more than 5 days ago

$ find my_folder -mtime +5

21|0show a calendar

STOP LOOKING UP WHAT THIS MONTH LOOKS LIKE BY CALENDAR WIDGETS 👎

Display a text calendar

$ cal

Display selected month and year calendar

$ cal 11 2018

22|0find a future date

STOP USING WEBAPPS TO CALCULATE FUTURE DATES 👎

What is todays date?

$ date +%m/%d/%Y

What about a week from now?

$ date -d "+7 days" # on Linux $ date -j -v+7d # on MacOS

23|0use a calculator

STOP USING CALCULATOR WIDGET 👎

$ bc

24|0force quit a program

STOP CTRL + ALT + DELETE and choose the program to kill 👎

$ killall program_name

24|1check server response

STOP OPENING A BROWSER 👎

curl -i umair.surge.sh # curl's -i (--include) option includes HTTP response headers in its output.

25|0view content of a file

STOP DOUBLE CLICKING A FILE 👎

$ cat apps/settings.py # if the file is too big to fit on one page, you can use a 'pager' (less) which shows you one page at a time. $ less apps/settings.py

26|0search for a text

STOP CMD/CTRL + F IN A DIRECTORY 👎

$ grep -i "Query" file.txt

在这里插入图片描述

27|0view an image

STOP USING PREVIEW 👎

$ imgcat image.png # Note: requires iTerm2 terminal.

28|0show disk size

STOP RIGHT CLICKING DISK ICON OR OPENING DISK UTILITY 👎

$ df -h

29|0check performance of your computer

STOP OPENING YOUR ACTIVITY MONITOR OR TASK MANAGER 👎

$ top

30|0Quick tips

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lNXoXWbW-1624361305856)(./cli_tips.jpg)]

31|0Hotkeys

Ctrl + A Go to the beginning of the line you are currently typing on Ctrl + E Go to the end of the line you are currently typing on Ctrl + L Clears the Screen, similar to the clear command Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line. Ctrl + H Same as backspace Ctrl + R Lets you search through previously used commands Ctrl + C Kill whatever you are running Ctrl + D Exit the current shell Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it. Ctrl + W Delete the word before the cursor Ctrl + K Clear the line after the cursor Ctrl + T Swap the last two characters before the cursor Esc + T Swap the last two words before the cursor Alt + F Move cursor forward one word on the current line Alt + B Move cursor backward one word on the current line Tab Auto-complete files and directory names

__EOF__

本文作者艾孜尔江
本文链接https://www.cnblogs.com/ezhar/p/14920006.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   艾孜尔江  阅读(72)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2020-06-22 Windows10应知应会
2020-06-22 VSCode常用设置
点击右上角即可分享
微信分享提示