Unix Commands Exercise -- Annotated History File from Sept 30, 2003

File Commands: ls

[chuong@cbag chuong]$ ls <-- List the files in the directory
bash_history
[chuong@cbag chuong]$ ls -al <-- List all files in the directory including hidden files in long format
total 56
drwx------ 4 chuong chuong 4096 Sep 30 16:41 .
drwxr-xr-x 29 root root 4096 Sep 30 16:28 ..
-rw------- 1 chuong chuong 20 Sep 28 15:31 .bash_history
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-rw-r--r-- 1 chuong chuong 24 Feb 11 2003 .bash_logout
-rw-r--r-- 1 chuong chuong 191 Feb 11 2003 .bash_profile
-rw-r--r-- 1 chuong chuong 124 Feb 11 2003 .bashrc
-rw-r--r-- 1 chuong chuong 5531 Feb 4 2003 .canna
-rw-r--r-- 1 chuong chuong 847 Feb 20 2003 .emacs
-rw-r--r-- 1 chuong chuong 120 Feb 27 2003 .gtkrc
drwxr-xr-x 3 chuong chuong 4096 Aug 12 2002 .kde
drwxr-xr-x 2 chuong chuong 4096 Sep 24 18:01 .xemacs
-rw-r--r-- 1 chuong chuong 220 Nov 28 2002 .zshrc
[chuong@cbag chuong]$ ls -l <-- List file in long listing format
total 4
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
^d = directory
 ^^^read/write/execute for user
      ^^^read/write/execute for group
           ^^^read/write/execute for other

 

File Commands: chmod

[chuong@cbag chuong]$ ls
bash_history test.txt
[chuong@cbag chuong]$ ls -l
total 8
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-rw-rw-r-- 1 chuong chuong 11 Sep 30 18:10 test.txt

How would you change the permission of a file so the user and the group does not have write access to the file test.txt?

[chuong@cbag chuong]$ chmod ug-w test.txt
[chuong@cbag chuong]$ ls -l
total 8
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-r--r--r-- 1 chuong chuong 11 Sep 30 18:10 test.txt

How would you change the permission of a file so the user,group, and other (i.e. all) execute the file test.txt?
[chuong@cbag chuong]$ chmod a+x test.txt
[chuong@cbag chuong]$ ls-l
-bash: ls-l: command not found
[chuong@cbag chuong]$ ls -l
total 8
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:10 test.txt
[chuong@cbag chuong]$ clear <-- simply clears the screen

 

File Commands: mv, cp

[chuong@cbag chuong]$ cat test.txt <-- concatenates and display files
kdjsalkfja
[chuong@cbag chuong]$ pwd <-- shows your current location in the directory path
/home/chuong
[chuong@cbag chuong]$ cp test.txt new_test.txt <-- copy this file to a new file;
                                                                          <-- the content of both files are the same
[chuong@cbag chuong]$ ls -l <-- list files in long list format
total 12
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:25 new_test.txt
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:10 test.txt
[chuong@cbag chuong]$ mv new_test.txt new_test2.txt <-- move file 1 to new file; also renaming file
[chuong@cbag chuong]$ ls -l
total 12
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:25 new_test2.txt
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:10 test.txt
[chuong@cbag chuong]$ mkdir temp_dir
[chuong@cbag chuong]$ ls -l
total 16
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:25 new_test2.txt
drwxrwxr-x 2 chuong chuong 4096 Sep 30 18:26 temp_dir
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:10 test.txt
[chuong@cbag chuong]$ rmdir temp_dir
[chuong@cbag chuong]$ ls -l
total 12
-rw------- 1 chuong chuong 1633 Sep 30 16:41 bash_history
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:25 new_test2.txt
-r-xr-xr-x 1 chuong chuong 11 Sep 30 18:10 test.txt