The command line is offered by a program called your 'shell'.
Your shell by default is called 'bash', the Bourne Again Shell.
Bash could be replaced by another program if you wanted.
Standard commands are ...
Command |
Example |
Works with |
Function |
ls |
ls /tmp |
Both |
List files (like dir) |
ls -l |
ls -l /tmp |
Both |
List files long format |
cp |
cp src dest |
None |
Copies files |
mv |
mv oldname newname |
None |
Moves or changes the name of a file. |
rm |
rm oldfile |
None |
Deletes a file |
rm -rf |
rm -rf / |
None |
Deletes an entire subtree. |
df |
df |
Out |
Shows free disk space. |
du |
du /tmp |
Out |
Shows space used by a subtree |
cd |
cd |
None |
Change current dir to home dir. |
cd |
cd /tmp |
None |
Change current dir to given dir. |
chmod |
chmod a+rwx filename |
None |
Change permissions. |
chmod -R |
chmod -R go-rwx . |
None |
Change permissions for a whole subtree. |
chown |
chown randy /home/randy |
None |
Change owner. |
chown -R |
chown -R randy /home/randy |
None |
Changes a whole subtree. |
less |
less /tmp/README |
In |
Shows file to the screen. |
grep |
grep BUGS /tmp/README |
Both |
Shows lines containing the pattern to the screen. |
grep -v |
grep -v BUGS /tmp/README |
Both |
Shows lines NOT containing the pattern to the screen. |
cat |
cat file1 file2 |
Both |
Concatinates the files. |
whoami |
whoami |
Out |
Tells your current username. |
su |
su randy |
None |
Changes your current username. |
time |
time du /tmp |
Out |
Tells how long the command takes to run. |
sort |
sort /tmp/file-list |
Both |
Prints files in alphabetic order. (-r reverses order). |
sort -n |
sort -n /tmp/list-of-numbers |
Both |
Prints files in number order. (-r reverses order). |
head |
head -20 /tmp/list |
Both |
Prints only the first twenty lines. |
tail |
tail -20 /tmp/list |
Both |
Prints the last twenty lines. |
Commands can be combined.
To run commands consecutively, try seperating them with a
semi-colon.
ls; df; du
To run commands simultainiusly, seperate them with a '&'.
rm -rf /tmp & rm -rf /junk
To run commands and not wait for them to finish, end the command
line with a '&'.
rm -rf /junk &
To put the output of one command into the input of another,
seperate them with a pipe.
ls | sort
To place the output of a command into a file, use a greater-than
symbol.
ls > file-list
To have a command read from a file, use a less-than symbol.
sort < file-list
Questions
How do I make a folder named 'fred'?
How do I copy the file /etc/passwd into that folder?
The file /etc/passwd lists all users. Who is the first user alphabetically?
How would you see all files that start with an “a” in /usr/bin?
How would you count them?