Some Handy Linux Commands

October 31, 2007

Here are some commands I use ALL THE TIME when working on a web server through SSH. I'll try to update it as I think of other stuff that comes in handy.

Create Tarball

This will create an archive of "folder_name" called "folder_name.tar.gz".
tar -czpf folder_name.tar.gz folder_name

Recursively Find a String Within Files

This will find all occurances of "something" within all HTML files. Prints the results in the terminal
find ./ -name '*.html' -exec grep "breadcrumbs.inc.php" '{}' \; -print

Search and Replace within a File

This will find a "b" and replace it with "strong" in the file index.html
sed -i 's/b/strong/g' index.html

Disk Space / Disk Usage

Shows the disk space available and disk space used on each device.
du -d 1 | sort -n -r

Directory Space Used

Shows the disk space used by each directory (in current directory). Linux:
du -h --max-depth=1 | sort -n -r
FreeBSD:
du -d 1 | sort -n -r
Categories: Linux, Web Development

2 Comments about "Some Handy Linux Commands"

November 23, 2007 at 05:51 AM
Ah! Not that I see my comment waiting moderation, I see that the website software fiddled with the post and replaced my leading single quote with a backtick. That's very inconvenient for someone trying to be precise.
November 23, 2007 at 05:48 AM
In the 'find' command above, filenames are surrounded by a backtick (`) and a single quote ('). I think they should both be single quotes, e.g.: '{}'.

Leave a Comment about "Some Handy Linux Commands"

Your Name:
(Required)
Website URL:
(Optional)
Comment:
(No HTML. Newlines and URLs okay.)
Enter CAPTCHA:
 
 
 
 
Share