Bash Commands List Flashcards
All of the bash commands defined in the bash commands list
pwd
Report the path for the present working directory (cur-
rent directory)
cat
Read one or more files and write them out one after
another to standard output (often used as a quick way
to look at the contents of a small file). Usage: cat file
or cat file1 file2 file3
ls
List files in the current direction. Usage: ls or ls path
ls -la
Long listing including all files
ls -R
List recursively for all subdirectories
who
Report who is logged in
pinky
Give information about a user. Usage pinky -l username
date
Report the system time
cd
Change current directory
mkdir
Make a directory
rm
Remove files
rm -r
remove directories
rm -i
remove interactive mode
cp
Copy one or more files. Usage: cp old file new file or
cp file1 file2 . . . directory
cp -r
Copies everything
mv
Move files to new filenames or new directories. Usage:
mv old name new name or cp file directory
mv -i
Prompt before overwriting anything
more
Display the contents of a file to the user one page at a
time. Pressing spacewill let yougo on to the next page.
Usage: more file
man
Provide online documentation for Unix commands, system calls, configuration files and other features. Usage:
man command name
head
Print the first ten lines of each file parameter (or from
stdin if no parameter is given). Usage: head file
head -n num
Print the first num lines of a file
Usage: head -n num filename
tail
Print the last ten lines of each file parameter (or from
stdin if no parameter is given). Usage: tail file
tail -n num
Print the last num lines of a file
touch
Bring the modification time of a file up to the current
time. Also, create an empty file if it doesn’t already
exist. Usage: touch file
touch -t
Sets modification time for a file to a specific time
Usage: touch -t [YY]YYMMDDHHMM[.ss] oldfile
ps
Show currently running processes
ps -e
Report every process
ps -l
Provide a long listing
jobs
Show all processes that your shell is keeping up with
along with their job numbers (shell builtin)
bg
Move a suspended process into the background (shell
builtin). Usage: bg job number
fg
Move a backgrounded or suspended job to the fore-
ground (shell builtin). Usage: fg job number
kill
Send a signal to a process asking it to terminate. Usage:
kill process id
killall
Kill all processes running a given command. Usage:
killall command name
echo
Just print out its string parameters. Often used with
variable expansion to generate output from a shell
script. Example: echo ”My home is $HOME”
echo -n
Don’t automatically print a newline at the end
of the output
env
Report exported environment variables
grep
Read from files listed on the command line (or stdin)
and report lines that match a given pattern. Usage:
grep pattern file1 file2 . . . Example: grep ”printf”
test.h test.c
grep -v
Report only lines that don’t match the given
pattern.
grep -c
Don’t report matching lines, just print the number of lines that match in each input file
grep -E
Interpret pattern as extended regular expression syntax
grep -i
Ignore case
grep -n
Prefix each reported match with the line number
grep -q
Quiet mode. Don’t print anything. Just use the exit status to report whether or not a match was
found.
find path [options]
Recursively search directories to find matching files. By default, just print out matching pathnames.
Usage: find path options
find path -print
Print out each matching path.
find path -type f
Only report matching files.
find path -type d
Only report matching directories.
find path –mmin -n
Report files modified less than n minutes ago
find path –mmin +n
Report files modified more than n minutes ago.
find path –mtime [+-]n
Report files modified more/less than n days ago
find path -exec command
Execute command for each
matching file
stat
Display information about files. Usage: stat options file
stat -c ‘%s’
Report size in bytes
stat -c ‘%U’
Report name of the owner
stat -c ‘%G’
Report group ownership of the file.
sort [options] file
Sort lines of given file (or stdin) and output them in sorted order. Usage: sort file or sort
sort -n file
Interpret each line as a number and sort by magnitude.
sort -r file
Sort in reverse order.
wc file
Report the number of bytes, words and lines in a file
wc -c file
Just report number of bytes
wc -w file
Just report the number of words
wc -l file
Just report the number of lines
chmod
Change the permissions on a file or directory. Usage: chmod options file
chmod +x
Add execute permissions
chmod -w
Remove write permissions
chmod u+w
Add write permissions for the user that owns the file
chmod g+r
Add read permissions for the group that owns the file
chmod o-x
Remove execute permissions for others (other than the file’s owner or group)
chmod a+r
Add read permissions for everyone