Basic Linux Commands
Posted on June 1st, 2008 in Linux |
|
cd (change directory) |
|
|
cd myfolder |
Changes the current working directory to “myfolder” |
|
cd .. |
Go up one level to the current working directory. |
|
cd ../.. |
Go up two levels to the current working directory. |
|
cd / |
Changes the current working directory to the root directory. |
|
cd ~ |
Changes the current working directory to your home directory. |
|
mkdir (Make directory) |
|
|
mkdir Photos |
Create a new folder called “Photos” in the current directory. |
|
mkdir /Photos |
Create a new folder called “Photos” in the root directory. |
|
mkdir ~/Photos |
Create a new folder called “Photos” in your home directory. |
|
ls (list) |
|
|
ls |
list the file names in the current working directory. |
|
ls -l |
list the file names with “long” description/information (size, privilages, etc) |
|
ls -a |
list “all” file names in the current working directory including the hidden files. |
|
ls -l *.jpg |
list the file names ending in “.jpg” and display it in “long” description format(-l) |
|
cp (copy) |
|
|
cp my.cnf /etc/my.cnf |
Copy the file “my.cnf” and put it inside the root -> etc folder. |
|
cp tax05.db ~/Taxes |
Copy the file name “tax05.db” and put it inside my home directory -> Taxes folder |
|
cp “.jpg ~/Photos |
Copy all the files with “.jpg” extention and put them inside my home directory -> Photos folder |
|
cp -R ~/Docs /backups/’Docs Backup’ |
Copy the entire “Docs” directory from my home page and put it inside the root -> backups and call it “Docs backup” (use quotes if you use folder names with space. example: ‘Docs Backup’ (-R stands for “Recursive”) |
|
mv (Move or Rename) |
|
|
mv badletter.txt niceletter.txt |
Rename the file “badletter.txt” to “niceletter.txt” in the current directory. |
|
mv Pictures Photos |
Rename the folder “Pictures” to “Photos” in the current directory. |
|
mv *.jpg ~/Photos |
Move all the files with “.jpg” extention and put them inside my home directory -> Photos folder |
|
rm (Remove) |
|
|
rm ~/BadPhotos/*.jpg |
Delete all the files with the ‘.jpg’ extention inside your home directory -> “BadPhotos” folder. |
|
rm -R Temp |
Delete the “Temp” directory and all of its contents in the current directory (-R stands for “Recursive”) |
|
rm -fr Temp |
Delete the “Temp” directory and all of its contents including write-protected files without prompting in the current directory (-f stands for “force” -r stands for “recursive”) |
|
find (files and folders) |
|
|
find ~ -name myletter.doc -print |
Search for the file names “myletter.doc” inside my home directory and print the result to the screen |
|
sudo find / -name mysql -print |
Search for the file and folder names “mysql*” starting from the root directory and everywhere within it and print the result to the screen. (use “sudo” to get root access temporarily.) |
|
find . -name myletter.doc -print |
Search for the file names “myletter.doc” inside the current directory and print the result to the screen |
|
find . -name ‘myletter*’ -print |
Search for the file names starting “myletter” inside the current directory and print the result to the screen |
|
locate (similar to find) |
|
|
locate ~ -name myletter.doc |
Search for the file names “myletter.doc” inside my home directory and print the result to the screen |
|
pwd (print working directory) |
|
|
pwd |
Displays the pathname of the current working directory. |
|
who (who logged in) |
|
|
who |
Displays who is logged into the system. |
|
who am i |
Displays my user name. |
|
who -uH |
Displays who is logged into the system including heading “H” and idle time information. |
|
su (set user) - type exit to switch back to your own identity |
|
|
su |
Temporarily become the root user. (this will give you root access privilages and the most control over the OS) - it will prompt you for the administrator password. |
|
su username |
Temporarily become another user called “username” (replace “username” with the user that you wish to use as your new identity - this will give you access privilages for the “username”) - it will prompt you for the that user’s password. |
|
sudo (set user and do . . . . . . ) - similar to su except ’su’ will give you prompt but ’sudo’ you can start typing commands right after the ’sudo’ command. |
|
|
sudo find / -name mysql -print |
Temporarily changes your identity to the root user so you can search for all the files including the once that require root access privilage. It prompts you for administrator/root password |
|
sudo Bobuser rm /Users/Bobuser/Photos/myphoto.jpg |
Temporarily changes your identity to the “Bobuser” identity so you can delete a photo named “myphoto.jpg” from the home directory -> Photos folder belonging to Bobuser - It prompts you for “Bobuser”’s password. |
|
ps (running processes) |
|
|
ps -aux |
List detailed information on all running processes. |
|
top (CPU-intensive processes currently running) - press the “q” key to quit the “top” utility |
|
|
top -us10 |
List all running processes sorted by CPU usage - descending and updating every 10 seconds - don’t forget to press the “q” key to quit, otherwise it will run continuously. |
|
kill |
|
|
kill -9 160 |
Terminate the process ID # 160 at once without any hesitation. |


