arturoherrero/command-line-one-liners
حول
Command line one-liners.
أدوات التطويرالنمو المقاس للنجوم
- خلال 24 ساعة
- -١
- خلال 7 أيام
- ٠
- خلال 15 يومًا
- ٠
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلCommand line one-liners
After my article about command line one-liners, many people want to contribute with their own commands. This is the place to do it, pull requests are welcome!
Table of Contents
- History
- Directories
- Files
- Searching
- Networking
- User environment
- File system
- Date & Time
- Processes
- Miscellaneous
History
Run the last command
$ !!Run the last command as root
$ sudo !!Create a script of the last executed command
$ echo "!!" > script.shReuse all parameter of the previous command line
$ echo cd . $ !*Run the last command with some argument
$ echo a b c d e $ echo !!:2 $ echo !!:3-$Insert the last argument of the previous command
$ cp script.sh /usr/bin/ $ cd !$ $ cd <ESC> . $ cd <ALT> .Runs previous command but replacing
$ echo no typos $ ^typos^errorsEscape any command aliases
$ alias ls="ls -a" $ \lsRun a command from the history
$ history ... 1225 ls -l 1226 git status 1227 history $ !-3 $ !1225Search the history for the most recent command beginning with
text$ !textSearch the history for the most recent command containing
text$ <ctrl-r>textList of commands you use most often
$ history | awk '{print $2}' | sort | uniq -c | sort -rn | headExecute a command without saving it in the history
$ <space>command
Directories
Make a directory creating intermediate directories
$ mkdir -p a/long/directory/pathCreate a directory and change into it
$ mkdir dir && cd $_Change to the previous working directory
$ cd -Jump to a directory. Execute a command in a subshell. Jump back to current directory
$ (cd /tmp && ls)
Files
Quickly rename a file
$ mv filename.{old,new} $ mv filename.{png,jpg}Create a quick back-up copy of a file
$ cp file.txt{,.bak}Create a simple text file from command line
$ cat > file.txt {your text here} {your text here} <ctrl-d>Create a simple text file from command line or script (
EOFis just a token, can be any word)$ cat > file.txt << EOF {your text here} {your text here} EOFEmpty a file from command line (usefull to truncate log file from running processes)
$ > file.txtEmpty a file from command line or script
$ cat /dev/null > file.txtMake
lessbehave liketail -f$ less +F somelogfileDisplay line numbers in a file
$ cat -n file $ less -N fileRedirect standard input to a file. Print it to standard output
$ command | tee file.txt | less ┌─────────┐ ┌─────────┐ ┌─────────┐ │ command │─▸│ tee │─▸│ stdout │ └─────────┘ └────┬────┘ └─────────┘ │ ▾ ┌───────────┐ │ file │ └───────────┘
Searching
Search for a string inside all files in the current directory
$ grep -RnsI --color=auto <pattern> *Beyond grep
_ /| \'o.O' =(___)= U ack! $ ack <pattern>Recursively remove all empty directories
$ find . -type d -empty -delete
Networking
Serve current directory tree at
http://$HOSTNAME:8000/$ python -m SimpleHTTPServer $ ruby -run -e httpd . -p 8000Share a file between two computers
receiver $ nc -l 5566 > data-dump.sql sender $ nc <receiver-ip-address> 5566 < data-dump.sqlShare a BIG file between two computers and show progress bar
receiver $ nc -l 5566 > big-file.iso sender $ pv big-file.iso | nc <receiver-ip-address> 5566Transfer a folder between two computers
receiver $ nc -l 5566 | tar -zxv sender $ tar -zcv <folder> | nc -w1 <receiver-ip-address> 5566Download an entire website
$ wget -m -k http://website.com
User environment
Show
PATHin a human-readable way$ echo $PATH | tr ':' '\n' $ tr ':' '\n' <<< $PATHClear the terminal screen
$ <ctrl-l> $ clearSalvage a borked terminal
$ resetClose shell keeping all subprocess running
$ disown -a && exitRun a command immune to hangups
$ nohup command &
Networking
Attach screen over ssh
$ ssh user@host -t screen -rCompare a remote file with a local file
$ ssh user@host cat /path/to/remotefile | diff /path/to/localfile -Get your public IP address
$ curl ifconfig.meSet audible alarm when an IP address comes online
$ ping -a IP_addressList programs with open ports and connections
$ lsof -iCheck which process is listening on a specific port
$ netstat -nlp | grep 8080 $ netstat -nlp tcp | grep 8080 (BSD)
File system
Currently mounted filesystems in nice layout
$ mount | column -tDisplay free disk space
$ df -hDisplay disk usage statistics for the current directory
$ du -sh *Display 10 biggest files/folders for the current directory
$ du -s * | sort -nr | headCreate a zip archive of a directory
$ zip -r archive.zip directoryExtract compressed archive
$ unzip archive.zipShow File System Hierarchy
$ man hier
Date & Time
Shutdown the system at a given time
$ shutdown -h now $ shutdown -h 22:49Execute a command at a given time
$ echo "ls -l" | at midnightSimple stopwatch
$ time read <ctrl-d>Put a console clock in top right corner
$ while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &Displays a calendar
$ cal 12 1984What day was yesterday or will it be tomorrow, etc...
$ date -d yesterday $ date -d tomorrow +%Y-%m-%d $ date -d "7 days ago" +%Y-%m-%d $ date -j -v-1d (BSD)
Processes
Display the top ten running processes. (Sorted by memory usage)
$ ps aux | sort -nk +4 | tailKill all Ruby processes
$ ps aux | grep ruby | awk '{ print $2 }' | xargs kill -9 $ ps aux | awk '/ruby/ && ! /awk/ { system("kill -9 "$2) }' $ pkill -f ruby $ killall -9 rubyCheck which process is modifying a certain directory or file
$ auditctl -w /path/to/directory -p warSee results
$ ausearch -f /path/to/directory
Miscellaneous
32 bits or 64 bits?
$ getconf LONG_BITQuick access to the ascii table
$ man asciiCount your commits
$ git shortlog -snRussian Roulette in Bash (remember kids don't try this at home)
$ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live"Watch Star Wars via telnet
$ telnet towel.blinkenlights.nl
Who made this?
This was made by Arturo Herrero under the MIT License. Find me on Twitter @ArturoHerrero.
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…