290 likes | 540 Views
Basic Unix Commands. Listing files and directories. ls :command is used to list the files and directories in present working directory ls command is most used command syntax: ls Lists the files and directories in present working directory. ls. Display One File Per Line Using ls -a
E N D
Listing files and directories ls:command is used to list the files and directories in present working directory ls command is most used command syntax: ls Lists the files and directories in present working directory
ls Display One File Per Line Using ls -a To show hidden files means . Files in unix
ls Display All Information About Files/Directories Usingls -l To show long listing information about the file/directory. $ ls -l -rw-r----- 1 srinivas team-dev 9275204 Jun 13 15:27 mthesaur.txt.gz 1st Character – File Type: - normal file d directory
ls Field 1 – File Permissions Field 2 – Number of links Field 3 – Owner Field 4 – Group Field 5 – Size Field 6 – Last modified date & time Field 7 – File name
Display File Size in Human Readable Format Using ls -lh Use ls -lh (h stands for human readable form), to display file size in easy to read format. i.e M for MB, K for KB, G for GB. $ls -lh -rw-r----- 1 srinivas team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
cd cd command is used to change the directories options: cd .Current directory cd .. back to one directory cd ../../ go back two directories.
Pathnames Use the pwd command to print the working directory (the current directory you are in) $ pwd /home $ cd /home/rich/www $ pwd /home/rich/www $
Creating Directories mkdir :command is used to create directories The syntax for the mkdir command is: mkdir directoryname
Copying Files cp:command is used to copy files one one directory to another directory syntax : cp source destination
Moving Files The mv command is used to move a file from one directory to another directory we can also use this command to renaming a file Syntax: mv fromsource todestination mv a.txt b.txt The above command changes file name “a to b”
Removing Files and directories rm : this command is used to remove files and directories syntax: rm [option] file/directory the -rf option can be used to remove the directories and sub directories. rm -rf directoryname
Displaying the contents of a file on the screen In unix we have multiple commands to display the content of a file on the screen some of them are 1.more 2.cat 3.vi editor
more The more command displays the content of a file on the screen syntax: more filename We can't modify the content of a file using more command this is used just for display file content only
cat command Using cat command we can read and modify the content of a file. We can use this command to concatenate files 1.reading a file syntax:cat filename 2.appending text to a file syntax: cat >> filename 3.Over writing file content syntax: cat > filename