Linux Commands Part 5 - 8
Tags: linux-com-book
What are commands
An executable program
A program built into the shell itself
A shell function
A alias
Commands
to know command is of which type :
type command
to the exact location of executable :
which ls
in bash, to get info regarding shell built-ins :
help cd
to display program’s manual page :
man program
to search the list of man pages for possible matches based on a search term
to display one-line manual page description :
whatis ls
alternative to man page :
info coreutils
to create alias command :
alias foo=”cd programm && code .”
Input Output Commands
to redirect standard output to a file :
[me@linuxbox ~]$ ls -l /usr/bin > ls-output.txt
“>” also clears the whole file and adds the new content
“>>” will append the content to the file at the end
Error message aren’t send to file unless specified in the command, they are sent to standard error
There are 3 types of file streams
Input
Output
Error
Pipelines
The capability of commands to read data from standard input and send to standard output.
to view a long output :
ls -l /usr/bin | less
Pipelines are used along with filter
Ex :
ls -l /usr/bin | sort | less
The Difference Between > and |
Simply put, the redirection operator connects a command with a file, while the pipeline operator connects the output of one command with the input of a second command.
uniq
is used to remove duplicate lines, mostly placed after sortwc
: to print Print Line, Word, and Byte Counts :wc names.txt
grep to filter out using keyword :
ls /bin /usr/bin | sort | uniq | grep zip
head
to print the first part of file-n x
to print first/last x lines
tail
to print the last part of file-f
to keep watching file for changes
tee
: program reads standard input and copies it to both standard output (allowing the data to continue down the pipeline) and to one or more files
The world of Echo
print something to terminal
Arithmetic Expression
Brace Expression
use “” to print the string as it is
use ** to as escape character
!200
will give the command in history at line 200
Last updated