This page is about command in bash.
Command are in bash the expression unit
A command (or an expression) is a sequence of words separated by blanks, terminated by a control operator.
For the builtin bash function command, see Bash - Command (The Builtin command command)
Each command execution has an environment.
The default order for command lookup is:
There are three built-ins that you can use to override this order:
The return status (of Exit Status) is:
Thanks to array parameter expansion, you can build a command with an array
Example building the command ls -a
cmd=("ls")
cmd+=("-a")
# execution
"${cmd[@]}"
# Check the command $1
function check_command() {
command -v $1 -v 2>&1 > /dev/null || { echo >&2 "I require $1 but it's not installed. Aborting."; exit 1; }
}
Linux - man (Manual, Help, Documentation)
To create a shortcut of a command with parameters, see Bash - Alias (of a command) - Builtin command
With the command history:
$history
you will get an history of the command
1000 cat installation_overview_di.txt
1001 fc -l 999
1002 man fc
1003 history
1004 history|grep NQS
1005 ls -al
1006 ls -al
1007 dir
1008 history
The exclamation mark start a history command substitution, except when followed by a space character, tab, newline, = or (.
The 'fc' utility lists or edits and re-executes, commands previously entered to an interactive sh.
fc -l 999
will list the last 999 command
Command | Description |
---|---|
Network | |
ifconfig | To detect the IP Adress |
netstat -rn | routing table |
Ctrl+C | interruption of script |
hostname name | To set the hostname, name is the system name you want for your local machine (fully qualified domain name or not) |
Navigation / NFS | |
mkdir | make directory |
cd | change directory ( cd .. is the shortcut for moving up one directory level). ex. cd “Entreprise Linux 2007” |
ls | ls -a show the cached file |
mv | Changes the names of directories and subdirectories mv old_name new_name |
pwd | display the name of the current directory. The pwd command stands for “print working directory” |
which | give the path of a file. Ex : “which java” return “/usr/bin/java” |
ln | make links (short cut) between files |
df | Disk Free to know the used space (Example: df -h where h stands for human readable) |
rm | delete a file |
rmdir | delete a directory |
CD Rom | |
mount | On redhat linux 6 or below: mount /dev/hdc /mnt/cdrom and for above versions: mount /dev/cdrom /mnt/cdrom |
Environment | |
echo | To get the value of en environment variable (ex.: echo $ARBORPATH) |
env or set | A long list of bash environment variables appears |
Security | |
whoami | Return the current user |
Process | |
top | display top CPU processes |
Text Manipulation | |
grep | filters content based on certain strings |
sed | search and replace |
awk | sed and grep in one tool |