Working with Files


Let me tell you the secret of computers, of operating systems, and of the whole industry that surrounds these things: Everything is data. Information is the be-all and end-all of everything we do with computers. Files are the storehouses for that information, and learning how to manipulate them, use and abuse them, and otherwise play with them will still be the point of computers 20 years from now.

The next thing I want to do is talk about the three most overlooked files on your system: standard in, standard out, and standard error. A facility in manipulating these "files" will provide you with amazing flexibility when it comes to doing your work.

Commands to Know and Love, Part 2

ls

LiSt files.

cat

conCATenate files.

Try "cat /etc/profile".

sort

SORT the contents of a file (or any output for that matter).

Try "sort /etc/passwd".

uniq

Return only the UNIQue lines you do this after sorting.

wc

Word Count (returns a count of words, characters, and lines).

Try "wc /etc/passwd".

cp

CoPy files.

mv

MoVe, or rename, a file.

rm

ReMove, or delete, a file.

more

Allows easy paging of large text files.

less

Like the more command, but with serious attitude.


File-Naming Conventions

Valid filenames may contain almost any character. You do have to pay some attention to the names you come up with. Your Linux system will allow filenames up to 255 characters in length. How you define filenames can save you a lot of hassle, as I soon demonstrate.

Some valid filename examples include the following:

 fish duck program_2.01 a.out letter.to.mom.who.I.dont.write.often.enough.as.it.is .bash_profile 

Notice the last name in particular. It starts with a period. Normally, this type of file is invisible with a default listing. Starting a filename with a period is a way to make a file somewhat invisible. This is good to know if you don't want to burden file listings with a lot of noise. It is also the way that a system cracker might hide his or her tracks when breaking into your system by creating a directory that starts with a period. To see the so-called dot-files, use the ls command with a -a flag (ls -a).

Listing Files with Emotion!

The ls command seems so simple, and yet it has a number of options that can give you tons of information. Change to something like the /etc directory and try these options if you never have:

 cd /etc ls --color ls  b ls  lS ls  lt 

The first listing will show different types of files and directories in color. The second (-b) will show octal representations for files that might have been created with control characters. Depending on the terminal you are using, the default is to show question marks or simply blanks. If you need to access (or delete) the file, it helps to know what it is really called. The third and fourth options control sorting. The -lS option gives you a long listing (lots of information) sorted by file size. The last option (-lt) sorts by time, with the newest files at the top of the list and the oldest at the bottom.



Moving to Linux(c) Kiss the Blue Screen of Death Goodbye!
Moving to Linux: Kiss the Blue Screen of Death Goodbye!
ISBN: 0321159985
EAN: 2147483647
Year: 2003
Pages: 247

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net