Basic linux commands

Posted under » Linux on 30 September 2009

A lot of things cannot be done unless you are SUDO

sudo su -

list directory
very similar to DIR command in windows

ls // basic
ls -a // show hidden files
ls -a | less // cleaner version of list show hidden files
ls -l // this will show the owner and group
ls -t // normally it will sort alphabetically but you can sort by modified date
ls -lah // list in detail, file size, date etc.
ls *find* 
ls >> list2file.txt
ls -d // just the file name w path 

Sometimes you might want linux to suggest or auto complete eg. cd commands. To do this, you use the TAB button (my fav).

For past commands, you scroll using the up and down keys. If you want to look for much older commands,

history | less
history | more
history | grep firefox
You will see a long list. To execute one of them... take note of the number and !number or
$ !21 

Copy
Copies the contents of file1 into file2

cp file1 file2 

In some cases, it is preferable to use the "cp --preserve" option to maintain file permission etc.

cp -R -p fileori filecopy

-R means copy directories recursively

Cat

You can combine text or binary files into 1 using cat

cat *.txt > combined.txt
cat file1.txt file2.txt > combined.txt

You can quickly create a text file using cat

 cat > tocopy.txt

Awaits input from user, type desired text and press CTRL+D to exit. The text will be written in tocopy.txt file.

I normally use it to view text file/s.

 cat file1.txt file2.txt | less

Use with a combination of echo

$ echo "bread, eggs" > list.txt
$ echo "orange, apples" >> list.txt
$ echo "My Shopping List" | cat - list.txt

It has many other uses.

Move
Also known as rename. It will move directories too.

mv file1 file2 
mv documents /backups
mv * /www/hanafi

Remove

rm file1 file2 

The rm command deletes (removes) files AND directories.

rm -r directory
// stops the nagging when deleting hidden files
rm -rfv /dir/.* 2>/dev/null

If you want to look for files like .svn or delete folders and files recursively. You can combine rm with the find command.

PWD

Often it's useful to know your exact current directory. To find this out, type the command pwd (short for "print working directory")

Tips

TheĀ --helpĀ option displays a basic list of options.

Related

CHOWN & CMOD | Grep and finding things in Linux | Soft link | Reboot and Shutdown | Touch | Checking disk usage in linux | Tar archive

For more tips -> http://goo.gl/UGKpd

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data