Linux File commands Essay

Submitted By ihavenoarm
Words: 669
Pages: 3

File Commands
The following table describes several basic commands when managing files:
Use...
To...
Examples
touch
Create a blank file if the file does not exist, or to update the file's modification and last accessed times if the file exists. touch myfile makes a blank file named myfile. cat Display the contents of the file in the shell. This can include displaying multiple files at once. cat myfile displays the contents of the file myfile. cat myfile yourfile displays the contents of the file myfile and yourfile together. less Display the file one screen at a time.
Use the SpaceBar to scroll to the next screen.
Use the Up arrow and Down arrow to scroll up and down.
Type q to exit. less bigfile displays the contents of bigfile one screen at a time so it can be read. head List the first 10 lines of a specified file, by default. The -n option specifies a specific number of lines. head /home/user/myfile lists the first 10 lines of myfile. head -n 20 /home/user/myfile lists the first 20 lines of myfile. head -n -35 /home/user/myfile displays all lines in myfile, omitting the last 35 lines. tail List the last 10 lines of a specified file, by default. Options include:
-n specifies a specific number of lines.
-f monitors the file. tail /home/user/myfile lists the last 10 lines of myfile. tail -n 20 /home/user/myfile lists the last 20 lines of myfile. tail -n -15 /home/user/myfile displays all lines in myfile, omitting the first 15 lines. file Show the file type. The file command might often be necessary because Linux does not require file extensions. file uses file signatures in:
/usr/share/misc/magic
/usr/share/misc/magic.mgc
/etc/magic
file myfile shows whether myfile is a text, data, xml or other type of file. cp Copy files. Copying leaves the source file intact. Options include:
-f overwrites files that already exist in the destination directory.
-i prompts before overwriting a file in the destination directory. cp /temp/document_ab.txt ~/doc/document.txt copies document_ab.txt from the /temp directory to the ~/doc directory and renames the file to document.txt. cp /temp/*.txt ~/doc copies all text files from the /temp directory to the ~/doc directory. mv Move or rename files (and directories). Moving files erases the source file and places it in the destination. Options include:
-f overwrites files that already exist in the destination directory.
-i prompts before overwriting a file in the destination directory.
-n never overwrites files in the destination directory. mv /temp/document.txt ~/doc/document.txt moves