Fooling around on Linux Command Line

I have been a long time Linux user. I installed Slackware 2.3 with kernel version 1.2.8 which came with PC Quest magazine on a CD in 1996 on my then DOS 5.5 and Windows 3.1 PC. I became a Mandriva fan when I visited their booth at the Linux expo in 1999 held in New York and they gave me a CD of Mandriva 6.0. Today, I frequent between Mageia and Ubuntu. But there is no end to the things I keep learning on how to do things faster, better etc. in Linux and all from the command line.

I hope that this page will be a live document of some nice and some very useful Linux command line tricks. Here goes:

running the last command as Root> sudo !!
find your external IP address curl
empty any file without removing it > filename.txt
execute a command without saving it in the history _space_ command
backup a file before editing cp filename{,.bak}
traceroute with ping mtr
clear terminal screen ctrl-L
list of commands you use most often history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
run your previous command but replace “abc” with “xyz” !!:gs/abc/xyz
combine two pdf files gs -q sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER pdfFile1.pdf pdfFile2.pdf -sOutputFile=newFile.pdf
extract pages from a pdf file gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=startPageNumber -dLastPage=endPageNumber -sOutputFile=extractedPagesFile.pdf originalFile.pdf
identify the process listening on a port netstat -tulpn; ls -l /proc/processId/exe
find the process PID that opened port ABCXYZ fuser ABCXYZ/tcp or fuser ABCXYZ/udp
current working directory of a pid ABC ls -l /proc/ABC/cwd
owner of a process ABC ps aux | grep ABC
extract a small part of a video file starting at time specified by -ss and for time specified by -t ffmpeg -ss 00:00:30 -t 00:00:05 -i orginalfile -vcodec copy -acodec copy newfile
truncate a file to size 0 truncate -s 0 {filename.txt} OR cat /dev/null > largefile.txt OR cp /dev/null largefile.txt
passwordless SSH logins from a@A to b@B On A as 'a'
  1. ssh-keygen -t rsa -b 2048 (Don't enter a passphrase)
  2. ssh b@B mkdir -p .ssh
  3. cat .ssh/ | ssh b@B 'cat >> .ssh/authorized_keys'
  4. Done
create a colourful bash prompt export PS1="\e[0;32m[\u@\h \W]\$ \e[m " will give you a nice green prompt. Substitute 32 with 31 for red, 34 for blue and 36 for cyan. Check this list for more fun prompts and colours.
Sending HTTP POST requests from command line curl -d "param1=value1&param2=value2&param3=value3"
Sorted list of space used in a folder du --block-size=GiB --max-depth=1 | sort -n

Last Update: