VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1[2] ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 23:19:31 02/05/07 Mon
Author: Anandan
Subject: Commands2 - File and Directory commands
In reply to: Anandan 's message, "Unix - Basics, Commands, Editors & their commands" on 05:54:13 01/10/07 Wed

1.To change your current directory use cd
$cd /
$cd /home/xyz/device
$cd /usr/local/
To make your home directory as current directory,
$cd
or $cd ~

2 After changing your current directory, to go back to the last current directory,
$cd -

3. To get the current working directory
$pwd

4. To see the contents of current directory
$ls

To see the contents of specific directory say doc
$ls doc or $ls doc/

To view hidden files,
$ls -a

Using the -F option brings some order to a confusing directory:
$ls -F
bridge* data/ jre@ misc/ personnel/
Above, data/ misc/ and personnel/ are directories
bridge is an executable file
jre is a symbolic link.

To display the contents of a directory in one column use the -1 (number one) option
To display the contents with more information:
$ls -l (letter el)
rwxr-xr-x 2 root root 4096 Sep 26 15:13 backup
drwxr-xr-x 2 root root 4096 Sep 21 17:43 bin
drwxr-xr-x 3 root root 4096 Sep 21 14:50 boot
-rwxr-xr-x 1 root root 46754 Dec 20 18:29 BRIDGE-MIB
drwxr-xr-x 4 root root 4096 Nov 28 16:27 cair

To get the number of subdirectories and files,
$ls |wc -l (letter el)

To sort the contents use -x
$ls -x

combination of x and F as:$ls -xF

-t option to ls lists files in order of time (newest firest) instead of alphabetically.
$ls -t

5. ls -l discussed above also gives the permissions.To change the set permissions, use chmod command with argument specified below:
To make a file, user executable
$chmod 700 binx
400 - owner has read permission (alone)
200 - owner has write permission (alone)
100 - owner has execute permission (alone)
040 - group (to which owner belong) has read permission only
020 - group has write permission only
010 - group has execute permission only
004 - all users have write permission only
002 - all users have read permission only
001 - all users have execute permission only.

To give a combination of permissions add their corresponding codes:
Say for example 700 = 400+200+100 - Owner has write, read and execute permission.
To set user all the above permissions, group to have read and execute permission and all users to have execute permission only, use
$chmod 731

$chmod 777 give all permissions to all the 3 categories.

Instead of above codes one can use symbolic codes as given below:
$chmod u+x
sets the executable permission to owner in addition to existing access.
To remove write permission to the group,
$chmod g-w
To remove read and write permission and provide execute permission to all,
$chmod o-wr o+x

To give every user, every access,
$chmod ugo+rwx

6. To know the current access permissions to all files created
$umask
To change the permissions to give full access to the owner and group, but not to the others:
$umask 007
After running the above command, if you use $mask, you should get
770.
(The value after subtracting 007 from 777)

7. To change the ownership of a file,
$chown
To make, say kevin as the user of all the files of a directory say report/
$chown -R kevin report/

8. Moving files
$mv

To rename a file, one can use the same command
$mv

9. Copying files
$cp
To rename a file while copying
$cp

10. To copy directories
$cp -r /users/data /users/kevin

11. Removing files
$rm 2002.report
To remove multiple files,
$rm file1.txt file2.txt, file3.txt
To remove all txt files which start with file
$rm file*.txt
use -i option to confirm the deletion
# rm -i BRIDGE-MIB
rm: remove regular file `BRIDGE-MIB'?

12. Removing directories:
If the directory contains no files or subdirectories
$rmdir users/
To remove directory with all its contents (files & subdirectories)
$rm -rf users/

13. To create a directory:
$mkdir users
$mkdir users/kevin
$mkdir /home/kevin/report/ (if /home/kevin already exists)
To create multiple subdirectories,
$mkdir memos letters
To create a directory and a subdirectory when using the -p option:
$mkdir -p /memos/letters

14. Linking files
$ln address /users/etc/address
The syntax is ln original_file target_file

To create symbolic links,
$ln -s

15. Wild Cards
* - to match any number of characters in a string including zero characters
$ls report*
report report1 report8 report18 report23 reports reports12 reports.old reporters.note

? - used to match a single character in a string
$ls report?
report1 report8 reports
[...] Here one can ask Unix to match specified characters:
$ls report200[0123456]
report2001 report2003 report2006
$report.[Ee]rc
report.Erc report.erc
a - hyphen within [ ] can denote a range of characters
$ls report.[a-d]
can list
report.a report.b report.c report.d

16. To find files:
$find -name -print
Example: $find / -name report.a -print

[ Next Thread | Previous Thread | Next Message | Previous Message ]

[ Contact Forum Admin ]


Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.