The Coded One

programming, algorithms, discrete math, open-source

Handy Shell Commands

with 2 comments

shell

The Linux shell or sometimes called the command line or terminal is a text-based interface to the kernel. With the rise of GUI tools, some would think that there is no longer a need for this. But still, I am yet to find a GUI tool that can even compare with the simplicity, efficiency and power of the shell. For those who are new, here’s a list of commands that you might find helpful. Enjoy!

Basic Filesystem Commands

ls – list contents of directory
pwd – print working directory
mkdir – make directory
cd – change directory
du – display informatino about your directory
cp – copy file/directory
mv – move file/directory
touch – create a file
rm – remove file/directory. Be extremely careful when using this command because this will permanently delete your files.

Viewing a file

cat – display the contents of the file to standard output
head – display the first few lines of the file to standard output
tail – display last few lines of the file to standard output
more – paginate and display the file to standard output
less – like more but allows backward and forward navigation. Loads only a segment of the file initially so it is faster than opening a very large file in a text editor.

Searching

grep – select and print lines from a file (or a bunch of files) that match a pattern

Display processes containing a specific string
#ps -e | grep firefox

find – search for files in a directory hierarchy

Search in the current directory and all sub directories for a php file
#find . -name "*.php" -print

Apply a command to a set of file
#find . -name "*.php" -exec chmod 775 '{}' ;

Search for a string in a selection of files (-exec grep)
#find . -exec grep "echo" '{}' ; -print

locate – search for a file that has been indexed
sed – stream editor, used to perform basic text transformations on an input stream.

Replace all instances of “foo” with “bar” in oldfile and save to newfile
#sed s/foo/bar oldfile > newfile

Some System Commands

df – display information about your drives/partitions
top – display detailed information about processes
uptime – display how long the system has been running
free – display amount of free memory
ps – display running processes including PID
kill – kill processes
ifup – bring a network interface up
ifdown – bring a network interface down
useradd – adds a new system user
paswd – change the password of a user, not necessarily the current user.
su – login as superuser or system administrator
sudo – execute command as super user

Operators

| – take the output of one command and make it the input to another command.
> – take the output of a command and output to a file, overwrite any existing file
>> – take the output of a command and output to a file, append to any existing file.
< – make the contents of a file serve as the input to a command

Written by Mark Basmayor

April 6, 2008 at 9:15 pm

Posted in Linux, Ubuntu

Tagged with , , , ,

2 Responses

Subscribe to comments with RSS.

  1. may kulang ka…vi or emacs! heheh!

    daine

    April 11, 2008 at 3:38 am

  2. I plan to create an entire post for that one.
    Hehe. Cheers!

    marksman

    April 11, 2008 at 3:40 am


Leave a Reply