cat command

cat <filename>
Concatenates or combine files, the command is frequently used to display the contents of a specified file without pauses. It didn't stop even the screen is full, but when the output redirected to printer or modem, it is convenient.
The command can concatenate several files together into one file

cat A B C > Z

concatenates the output of A, B, and C in the specified order to Z while replacing the older content of it.
It can also append (>>) the output to another file thus preserving the prior content.

To use as standard input to a file

cat > z.txt

Till ^D pressed, all the typed content goes to file z.txt. Backslash works, but once the enter key pressed, it doe not allow to go to the previous line

When used with -n, it can number each line of a file

cat -n list.txt

-b option is used to only number lines that are not blank.
-v option is used to show the hidden characters, or control characters, that may not show up in an editor.

cd command

Changes directory
without option moves to the current user's home directory

cd

Changes to the parent directory

cd ..

Changes to spcified directory

cd </path/directory-name>

switch back to a previous working directory

cd -

show the last working directory from where moved

cd --

move to home directory from anywhere

cd ~

change working directory to current working directory

cd .

cp command

Copy specified file or files into specified directory

cp <filename1> </path/directory-name>
cp <filename1> <filename2> </path/directory-name>

Copy the entire directory into specfified directory

cp -r <directory-name> </path/directory-name2>

cp command options:

-a Used for archive files
-b Make a backup of each existing destination file but does not accept an argument
-f Force copying
-i Ask before overwrite
-l Hard link files instead of copying
-L Always follow symbolic links in the source
-n Do not overwrite an existing file
-P Never follow symbolic links in SOURCE
-p Preserve the specified attributes
-r Copy directories recursively
-s Make symbolic links instead of copying
-u Copy only when the SOURCE file is newer than the dest. file or when the destination file is missing
-v Verbose
-x Stay on this file system.

head  & tail command

Display the first 10 lines in the specified file

head <filename>

tail <filename>

To display 15 lines

head -15 <filename>

tail -15 <filename>

-n num: Prints the first ‘num’ lines instead of the first ten lines.
-c num: Prints the first ‘num’ bytes from the file specified.
-q: used if more than one file given
-v: By using this option, data from the specified file always preceded by its file name.

 

Next >> Linux Command Tricks – II