Professional Documents
Culture Documents
Unit 4
Working with Files and Directories
A_collection_of_data\n
A_stream_of_characters_or_a_"byte_stream"\n
No_structure_is_imposed_on_a_file_by_the_operating_system\n
\n = newline character
_ = space character
Full pathnames:
Start from / (the root directory)
Relative pathnames:
Start from the present working directory
home
.bash_profile
test doc c manuals rp c pgms
test1 suba
mon_report a
trio_ltr b
walrus
$ pwd
/home/tux1
$
$ cd doc (relative)
$ cd /home/tux1/doc (full)
$ cd ~tux1/doc (home)
$ cd /home/tux1
$ mkdir doc (relative pathname)
$ pwd
/home/tux1
$ rmdir doc test
rmdir: doc: Directory not empty
$
$ mkdir -p dir1/dir2/dir3
$ rmdir -p dir1/dir2/dir3
$ ls /home
tux1 tux2 tux3
Important options:
-l long listing (more information)
-a lists all files (including hidden)
-t lists files sorted by change date
-R lists contents recursively
$ ls -l
-rw-rw-r-- 1 tux1 penguins 512 Jan 1 11:10 docs
$ touch docs
$ ls -l
-rw-rw-r-- 1 tux1 penguins 512 Jan 1 15:37 docs
$ touch new
$ ls -l
-rw-rw-r-- 1 tux1 penguins 512 Jan 1 15:37 docs
-rw-rw-r-- 1 tux1 penguins 0 Jan 1 15:38 new
$ cp -R /home/tux1/doc /tmp
To rename a file:
$ mv doc documents
$ cd
$ pwd
/home/tux1
$ mv /tmp/walrus ./test/walrus2
To move a directory:
$ mv ./test /tmp
mv is recursive by default
$ cat walrus
"The time has come", the walrus said,
"To talk of many things:
Of shoes - and ships - and sealing wax -
Of cabbage - and kings -
And why the sea is boiling hot -
And whether pigs have wings."
$
$ less walrus
"The time has come", the walrus said,
"To talk of many things:
Of shoes - and ships - and sealing wax -
Of cabbage - and kings -
And why the sea is boiling hot -
And whether pigs have wings."
/tmp/test/walrus 1-6/6 (END)
$ strings /usr/bin/passwd
/lib/ld.so.1
__gmon_start__
__deregister_frame_info
__register_frame_info
...
$
© Copyright IBM Corporation 2006
Removing Files
With the rm command:
$ rm test/walrus2
$ ls test/walrus2
ls: rob: No such file or directory
$ ls -l
-rw-r--r-- 1 root root 4194304 Jan 1 13:31 large