New User Tutorial: Basic Shell Commands
Linux and all version of unix (including MacOS) have a very rich command line that can be used in many different ways to form very powerful commands. These commands can be joined together to do complex jobs in a very simple way. These are some of the basic commands to get you started.
ls – List Directory Contents
lsList files in the current directory
ls -lDisplay directory contents in a “long list” format.
ls -lahDisplay all files, including hidden, with a human-readable file size.
cd – Change Directories
cd /var/logChanges location to /var/log
cd ~Changes to your user’s home directory.
cd –Returns you to the previous directory you were working in.
cd ..Moves you one directory up/back in the directory structure.
cp – Copy a File
The cp command copies a file from one place to another, or can create a new copy of a file in the same location with a different name.
cp file.txt newfile.txtCopy file.txt to newfile.txt
cp -r /home/user/pics /home/user2/Recursively (meaning the directory and all of its contents) copy the pics directory from /home/user/ to /home/user2/
mv – Move and Rename Files
mv file.txt /home/user/newuser/Moves the file called file.txt to the directory /home/user/newuser/
mv oldfile.txt newfile.txtRenames the file oldfile.txt to newfile.txt
mkdir - Make Directory
mkdir filesMakes a new directory called files
rm – Remove a File (Delete)
rm file.txtDeletes the file called file.txt
rm -r filesDeletes the directory called files along with everything in it
rmdir - Remove Directory (Delete)
rmdir filesDeletes an empty directory called files
cat – Display File Contents
cat file.txtDisplays the entire contents of the file file.txt
locate - Locate a file
The locate - a.k.a. find - command is meant to find a file within the filesystem. If you don't know the name of a certain file or you aren't sure where the file is saved and stored, the locate command comes in handy.
locate -i filenameSearches the filesystem for filename ignoring case
ping - send a packet of data to another network device and time the reply
ping 184.108.40.206Sends a packet to 220.127.116.11 (Google's public DNS server) and waits for the reply
Get instructions for a particular command
man manGet help with the man command
man lsGet help on ls
w – List Active System Users
wDisplays a list of users who are logged in to the system through a remote shell or local terminal, what they are doing, and other relevant information.