9 Useful Basic Unix Commands
This article is targeted at people who are new to Unix & want to learn its most-used commands that are used in the terminal.
cd
cd ~/Projects
Unless you’re new to unix, I think everybody knows what this do. This commands will change your current terminal’s directory to another directory. For example, if you’re in a
directory and you want to change to b
directory, simply type cd b
. More complete explanation: link.
ls
ls
This command will list what files/folders you have in your current directory. To also view all hidden files/folders, type ls -a
.
mv
mv ./a.txt ./b.txt
This command can either move a file to another directory, or, like above, rename a file. The first argument (a.txt
) is the file while the second argument is the new file name (in case of renaming) or the directory (in case of moving a file). To move to a directory (say, b
directory), you can type mv a.txt b/
.
rm
rm ./a.txt
This command is used for removing a file. If you want to remove a folder, use rm -rf [folder_name]
.
mkdir
mkdir app
This command is used to create a new directory. You can create nested directory by using mkdir -p a/b/c
.
cat
cat ./a.txt
Unlike its names, cat
is used to show the content of a file. There are more uses of this command, but you can learn as you go.
ps -e
ps -e
This command is used to list processes currently running on the machine. If this command doesn’t work, try calling sudo ps -e
(you will learn more about sudo)
Mostly you only look at “PID” and “CMD” from the output.
kill -9
kill -9 [PID]
Like its name, kill -9
is used to remove a running process. You can get the PID from the process above.
grep
[some_command] | grep search_value
Grep is used to filter out results of a command. I can type ls | grep Doc
If I to get any file/folders in current directory that have “Doc” in it. grep
can be used with many command, as long as you place it after the |
character.
Combined with the ps -e
command, we can search for a process that we want to kill
For now, it’s enough to know the basic commands. Later on, if you found any difficulties, just google it.