file management commands cat cat command cat cal.txt cat command displays the contents of a file...

26

Upload: amberly-chase

Post on 20-Jan-2018

229 views

Category:

Documents


0 download

DESCRIPTION

cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).

TRANSCRIPT

Page 1: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…
Page 2: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

File Management commands

Page 3: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

catCat command

cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).

Page 4: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

Cat > filenameCat command

cat > cal.txt cat output the contents to a file here cal.txt. It is redirecting the contents to the file.

touch filename

Page 5: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

ls

ls command is most widely used command and it displays the contents of directory.

options ls will list all the files in your home directory, this command has

many options. ls -l will list all the file names, permissions, group, etc in long

format. ls -a will list all the files including hidden files that start with . . ls -lt will list all files names based on the time of creation, newer

files bring first. ls -Fxwill list files and directory names will be followed by slash. ls -Rwill lists all the files and files in the all the directories,

recursively. ls -R | more will list all the files and files in all the directories, one

page at a time.

Page 6: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

ls-rw-r--r-- 1 lnp5jb 777 Dec 18 lookup.icn

The first set of characters in the output from the command (-rw- r-- r--) gives the permissions. The username in the middle of the line (lnp5jb) is the owner of the file. This is user who created the file. The following fields tell you the number of characters in the file, the date it was created and the name of the file.

Page 7: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

mkdirmkdir mkdir deep will create new directory, i.e. here deep

directory is created.

Page 8: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

cdCd command.

cd sandeep will change directory from current directory

to sandeep directory. Use pwd to check your current directory and ls to see if sandeep directory is there or not. You can then use cd sandeep to change the directory to this new directory.

Page 9: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

headhead filename by default will display the first 10 lines of a

file.

If you want first 50 lines you can use head -50 filename or for 37 lines head -37 filename and so forth.

Page 10: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

tailTail command.

tail filename by default will display the last 10 lines of a file. If you want last 50 lines then you can use tail -50 filename.

Page 11: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

moreMore command. more command will display

a page at a time and then wait for input which is spacebar. For example if you have a file which is 500 lines and you want to read it all. So you can use

more filename

Page 12: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

wcWc command

wc command counts the characters, words or lines in a file depending upon the option.

wc filename

wc -l filename will print total number of lines in a file. wc -w filename will print total number of words in a

file. wc -c filename will print total number of characters in

a file.

Page 13: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

File command displays about the contents of a given file, whether it is a text (Ascii) or binary file. To use it type

file filename

Page 14: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

cpCp command.

cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory.

cp oldfile newfilecp –p olddir nerdir

If I want to copy oldfile to other directory for example /tmp thencp oldfile /tmp/newfile.

options available with cp are -p and -r . -p options preserves the modification time and permissions, -r recursively copy a directory and its files, duplicating the

tree structure.

Page 15: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

mvmv command is used to move a file from one

directory to another directory or to rename a file.

Some examples: mv oldfile newfile will rename oldfile to newfile. mv -i oldfile newfile for confirmation prompt. mv -f oldfile newfile will force the rename even

if target file exists. mv * /usr/bajwa/ will move all the files in current

directory to /usr/bajwa directory.

Page 16: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

lnLn command.

Instead of copying you can also make links to existing files using ln command.

If you want to create a link to a file called coolfile in /usr/local/bin directory then you can enter this command. ln mycoolfile /usr/local/bin/coolfile

Some examples: ln -s fileone filetwo will create a symbolic link and can exist across machines.

ln -n option will not overwrite existing files. ln -f will force the link to occur.

Page 17: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

rmRm command.

To delete files use rm command. Options:

rm oldfile will delete file named oldfile. rm -f option will remove write-protected files

without prompting. rm -r option will delete the entire directory as

well as all the subdirectories, (use with care)

Page 18: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

rmdirRmdir command.

rmdir command will remove directory or directories if a directory is empty.

Options: rm -r directory_name will remove all files even

if directory is not empty. rmdir sandeep is how you use it to remove

sandeep directory. rmdir -p will remove directories and any parent

directories that are empty. rmdir -s will suppress standard error messages

caused by -p.

Page 19: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

Misc Commands

Page 20: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

Misc CommandsMan ual command.

man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example.

man ls will explain about the ls command and how you can use it.

Page 21: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

bannerBanner command.

banner prints characters in a sort of ascii art poster.

banner aman will print aman on screen

Page 22: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

calCal command

cal command will print the calander on current month by default. If you want to print calander of august of 1965. That's eightht month of 1965. cal 8 1965 will print following results.

Page 23: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

clearClear command clear command clears the screen and puts

cursor at beginning of first line.

Page 24: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

echoecho commandThe echo command 'echoes' its argument to

the standard output. This means that in its simplest form it prints something out on screen. For example:

echo Hello - you type Hello - response from the shell

Page 25: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

wildcardsWildcardsWildcard characters can be used to identify directory

and file names. The wildcard character * is used to refer to any combination of characters. For example:

ls * - refers to all files cat test* - refers to all files starting with 'test', e.g.

'test', 'testing', 'test.c', etc. The wildcard character ? is used to refer to a single character. For example:

ls test? - refers to files starting with 'test' followed by a single character e.g. 'test1', 'test2', 'testz', etc.% cat test.? - refers to all files starting with 'test' with a single character after the full stop, e.g. 'test.c, test.f'

Page 26: File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here…

chmodThe command chmod is used to change the

permissions on a file. The format of this command is:

chmod mode filename