Replace commas with tabs
sed "s/,/\\t/g" in.dat >> out.dat
List directories recursively
ls -RAlph
Remove files with and extension from multiple directories
rm -Rvf /some/dir*/*.ext
Move files only if they are newer, and backup if they already exist
mv -vubi
-v: verbose
-u: update only
-b: backup
-i: interactive, ask for confirmation to overwrite
From here:
Quickly Find a PID with pgrep
pgrep ssh
Execute The Last Executed Command
!!
The !!
command is very useful when you forget to start a command with sudo :
apt-get update
sudo !!
Execute The Last Command Starting With …
!s
This will execute the last command used on the command line that started with s.
Last Argument
You can use the last argument from the last command by refering to it as $_
so you only need to type a long path like this once:
cp assignment.htm /home/phill/reports/2008/
cd $_
to go straight to the 2008 folder as well.
Select columns in a text file
cat in.dat | cut -f 1,2,3 > out.txt
This will select columns 1, 2 and 3 and delete the rest
Run a Command Repeatedly and Display the Output
watch -d ls -l
This will watch the current directory for any file changes and highlight the change when it occurs.
Quickly Log Out of a Terminal
You can quickly log out of a terminal session by using: CTRL+D
Navigate to the Last Directory You Were In
cd –
will take you to the last directory you were in.
Make Parent Directories the Smart Way
mkdir -p /home/make/all/of/these/directories/
Delete the Entire Line
If you’ve just typed a long string of commands that you don’t need to enter anymore, delete the entire line by using: CTRL+U,K. That is not easy. CTRL+U deletes whatever is to the left of the cursor and CTRL+K deletes what is to the right. If you are at the end of command, CTRL+U will do. Especially if you start typing password and you make a mistake. Alternatively, you can use CTRL+C, which discards the current typed command, and gives you a new line. CTRL+L will clear the screen.
Set the Time stamp of a File
touch -c -t 0801010800 filename.c
will show the time stamp as 2008-01-01 8:00. The format is (YYMMDDhhmm).
Command to File
fc
will open the last command from your shell history in the default editor. You can also specify a text editor. You can add a history line number or the first few letters of the most recent command.
fc -e vim wget
will open vim with the last shell command starting with wget. You can edit the command, and when you save and close kate, the command will execute.
Ampersand
Ending a command with &
runs the command with a new PID, releasing the command line back to you. Useful for running a background process.
Resetting your session
Instead of killing and re-starting your terminal session, you can merely type the command reset
. This will reset your terminal back to its defaults, clear the screen, and everything will be as it was before.
Set keyboard in X11
setxkbmap us,es,fi -option ctrl:nocaps -option grp:ctrl_shift_toggle -option terminate:ctrl_alt_bksp -option compose:rwin