Useful Linux Commands

Updated about 3 yrs, 10 mths ago (October 6, 2013). Know a better answer? Let me know!

Useful Linux Commands

This is a little list of basic commands I keep needing, but which I don’t use often enough to bother remembering (and now with some added basic commands for people who don’t know a lot of scary Linux stuff…). It’s basically an online sticky note. These may be specific to CentOS.

tail, grep and truncate

tail httpd/apache log, grep for specific content, and truncate to a certain width (in this case 160 characters, the width of my terminal)

tail -f /var/log/httpd/access_log | grep --line-buffered hardanswers.net | sed -u "s/^\(.\{160\}\).*$/\1/"

Or, to do the same thing without the grep

tail -f /var/log/httpd/access_log | sed -u "s/^\(.\{160\}\).*$/\1/"

To get the size of the terminal (the width in characters) to use in the above

stty size

manage running processes

List a running process that matches apache

ps -ef | grep apache

List all processes owned by a user, in this case, apache

ps -f -u apache

Kill a single process (where PID is the process ID, found from ps -ef | grep process_name above), or kill all processes by name (in this case, apache)

kill PID

killall apache

Download a website using wget

Recursively download a site using wget (in this case, recursive to level 2, downloading page requisites, converting links to work locally, and waiting 1 second between requests)

wget -rcpk -l 2 --wait 1 -e robots=off --random-wait --user-agent="" http://hardanswers.net/

See wget Recursive Retrieval Options for more.

More Information

For more information on:

 

Updated about 3 yrs, 10 mths ago (October 6, 2013). Know a better answer? Let me know!

Related categories [coloured].

Comment on this article (no HTML, max 1200 characters):