Linux Commands
The Linux Terminal
Section titled “The Linux Terminal”-
In UNIX, terminal is a text interface to interact with the OS. There are list of commands which user can use to interact with the OS.
-
Terminal is also called shell or console.
-
Command Prompt and Powershell are two such kind of interface provided by Windows OS.
-
In Ubuntu and most of the UNIX based OS a particular type of shell called Bash which is one kind of UNIX shell, is launched when you open any Terminal program. Zsh is another such popular shell for UNIX.
-
These UNIX shell like Bash and Zsh are command processors which takes commands from user, interprets it and executes the commands with the help of the underlying OS.
-
UNIX shells can also read commands from a file. Such kind of files are called Shell Scripts. In the next section we will explore this.
-
One such shell script is .bashrc which resides in
/home/directory. This shell script runs everytime you open an instance of Bash shell. -
In Ubuntu you can press
Ctrl + Alt + Tto open up an instance of the terminal.
Common Linux Commands
Section titled “Common Linux Commands”-
In UNIX a superuser or root is a user which has unrestricted access to all the commands, files, folders and resources of the system.
-
If you want to run any command as a superuser you need to prefix that command with
sudo. -
eg:
sudo chmod +x hello.sh
| Command | Function |
|---|---|
ls | List the files and folders in the current directory |
ls -l | -l flag is used with ls to list files and folders in the current directory with their permissions. |
ls -la | -la flag is used to list all the files and folders including hidden ones with their permissions. |
| Usage | Result |
|---|---|
mkdir folder1 folder2 | This command will create two folders, folder1 and folder2 in current directory. |
| Usage | Result |
|---|---|
cd ~ | This will take to to /home/ directory. In UNIX, tilde ~ is used to represent home directory. |
cd ~/catkin_ws | This will take you inside a folder named catkin_ws in home directory |
| Usage | Result |
|---|---|
echo "hello" | This will print the string hello in the terminal. |
echo "hello" >> file.txt | This will append the string hello at the end of file.txt. This won’t overwrite anything. |
echo "hello" > file.txt | This will append the string hello at the beginning of file.txt. This will overwrite. |
| Command | Function |
|---|---|
find . -type d -name "dir_name_start*" | List the files and folders in the current directory starting with “dir_name_start”. |
find . -type f -name "file_name.*" | Search for files starting with “file_name” with unknown extension. |
-
Search for “text” string inside any type of file.
Terminal window grep -rnw "text" -
Highlight & Show only the pre-defined text in the output of a command
Terminal window catkin build | grep "pkg_my_ros"
-
This command is used to find the location of an executable available to shell.
Terminal window which python# Output/usr/bin/python
-
This will print out the path of current directory you are in.
Terminal window pwd
-
This will print the content of
file.txtwith line numbers, in the terminal.Terminal window cat -n file.txt
-
This is very useful command in UNIX. If you are not sure how to use any command just call
man. -
manstands for manual.Terminal window man whichman catman findman grepman man