Working with Files


Let me tell you the secret of computers, operating systems, and 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 twenty years from now.

The next thing I want to talk about is 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.

cat /etc/profile

sort

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

sort /etc/passwd

uniq

Return only the UNIQue linesyou do this after sorting.

wc

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

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 allows filenames up to 255 characters in length. How you define filenames can save you a lot of hassle, as I will 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 dot (or a period, if you prefer). Normally, this type of file is invisible with a default listing. Starting a filename with a dot 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 cracker might hide her tracks should she break into your systemby creating a directory that starts with a dot. To see these so-called dot files, use the ls command with the -d flag (ls -d).

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:

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


The first listing shows different types of files and directories in color. The second (-b) shows 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 Ubuntu Linux
Moving to Ubuntu Linux
ISBN: 032142722X
EAN: 2147483647
Year: 2004
Pages: 201

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