Sunday, February 20, 2011

Linux | ls dan rm command

rm

you could delete each file individually with the following command:
rm Joe\name Joe\address Joe\phone Joe\Other\ssn\ Joe\Other\age

You could then use the rmdir command to remove the directories Other and Joe:

rmdir Joe/Other Joe

the command:

rm -r Joe

Finally, a trick. A common problem people run into is how to delete a file whose name starts with a -. For example, if you entered the command

rm -garbagefile

in an attempt to remove a file named -garbagefile, you would get the error message:

rm: illegal option -g

Try rm -help for more information.

This is because rm assumes that if its first argument starts with a - it is an option. The solution is to use a name that does not confuse rm. For example, you can use either the full pathname of the file or a relative pathname where you explicitly specify the current directory using ./. Thus, the following command would do the job:

rm ./-garbagefile

Reference::
http://www.linuxjournal.com/article/50

LS
-----

1) ls -t sorts the file by modification time, showing the last edited file first. head -1 picks up this first file.

$ vi first-long-file.txt
$ vi second-long-file.txt

$ vi `ls -t | head -1`

[Note: This will open the last file you edited (i.e second-long-file.txt)]

2)To show single entry per line, use -1 option as shown below.

$ ls -1 bin boot cdrom dev etc home initrd initrd.img lib


3) To show long listing information about the file/directory.


$ ls -l -rw-r----- 1 ramesh team-dev 9275204 Jun 13 15:27 mthesaur.txt.gz



Reference ::


http://www.thegeekstuff.com/2009/07/linux-ls-command-examples/#more-550

No comments: