SOURCE: http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt (I`ve just formatted it for easy reading)
I have marked with a * those which I think are absolutely essential Items for each section are sorted by oldest to newest. Come back soon for more!
- In bash,
ctrl-rsearches your command history as you type
- Input from the commandline as if it were a file by replacing
command < file.inwithcommand <<< "some input text" ^is a sed-like operator to replace chars from last commandls docs; ^docs^web^is equal tols web. The second argument can be empty.
!!:nselects the nth argument of the last command, and!$the last argls file1 file2 file3; cat !!:1-2shows all files and cats only 1 and 2
- More in-line substitutions: http://tiny.cc/ecv0cw http://tiny.cc/8zbltw
nohup ./long_script &to leave stuff in background even if you logoutcd -change to the previous directory you were working onctrl-x ctrl-eopens an editor to work with long or complex command lines
- Use traps for cleaning up bash scripts on exit http://tiny.cc/traps
shopt -s cdspellautomatically fixes yourcd folderspelling mistakes- Add
set editing-mode viin your ~/.inputrc to use the vi keybindings for bash and all readline-enabled applications (python, mysql, etc)
function lt() { ls -ltrsa "$@" | tail; }function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; }function fname() { find . -iname "*$@*"; }
:set spellactivates vim spellchecker. Use]sand[sto move between mistakes,zgadds to the dictionary,z=suggests correctly spelled words- check my .vimrc http://tiny.cc/qxzktw and here http://tiny.cc/kzzktw for more
htopinstead oftop
rangeris a nice console file manager for vi fans- Use
apt-fileto see which package provides that file you`re missing dictis a commandline dictionary- Learn to use
findandlocateto look for files - Compile your own version of
screenfrom the git sources. Most versions have a slow scrolling on a vertical split or even no vertical split at all
trash-clisends files to the trash instead of deleting them forever. Be very careful withrmor maybe make a wrapper to avoid deleting*by accident (e.g. you want to typerm tmp*but typerm tmp *)
filegives information about a file, as image dimensions or text encodingsort | uniqto check for duplicate linesecho start_backup.sh | at midnightstarts a command at the specified time- Pipe any command over
column -tto nicely align the columns
- Google
magic sysrqand learn how to bring you machine back from the dead
diff --side-by-side fileA.txt fileB.txt | pagerto see a nice diff
j.pyhttp://tiny.cc/62qjow remembers your most used folders and is an incredible substitute to browse directories by name instead ofcd
dropbox_uploader.shhttp://tiny.cc/o2qjow is a fantastic solution to upload by commandline via Dropboxs API if you cant use the official client- learn to use
pushdto save time navigating folders (j.py is better though) - if you liked the
psgrepalias, checkpgrepas it is far more powerful
- never run
chmod o+x * -R, capitalize the X to avoid executable files. If you want only executable folders:find . -type d -exec chmod g+x {} \;
xargsgets its input from a pipe and runs some command for each argument
- run jobs in parallel easily:
ls *.png | parallel -j4 convert {} {.}.jpg
- Don
t know where to start? SMB is usually better than NFS for most cases.sshfs_mount` is not really stable, any network failure will be troublesome python -m SimpleHTTPServer 8080shares all the files in the current folder over HTTP, port 8080ssh -R 12345:localhost:22 server.com "sleep 1000; exit"forwards server.coms port 12345 to your local ssh port, even if you machine is not externally visible on the net. Now you canssh localhost -p 12345from server.com and you will log into your machine.sleep` avoids getting kicked out from server.com for inactivity
- Read on
ssh-keygento avoid typing passwords every time you ssh
socat TCP4-LISTEN:1234,fork TCP4:192.168.1.1:22forwards your port 1234 to another machine`s port 22. Very useful for quick NAT redirection.
- Configure postfix to use your personal Gmail account as SMTP:
http://tiny.cc/n5k0cw. Now you can send emails from the command line.
echo "Hello, User!" | mail [email protected]
- Some tools to monitor network connections and bandwith:
lsof -imonitors network connections in real timeiftopshows bandwith usage per connectionnethogsshows the bandwith usage per process
- Use this trick on
.ssh/configto directly accesshost2which is on a private network, and must be accessed by ssh-ing intohost1first Host host2 ProxyCommand ssh -T host1nc %h %pHostName host2 - Pipe a compressed file over ssh to avoid creating large temporary .tgz files
tar cz folder/ | ssh server "tar xz"or even better, usersync
(CC) by-nc, Carles Fenollosa [email protected] Retrieved from http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt Last modified: vie 08 mar 2013 10:52:46 CET