Skip to content
  • 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 + T to open up an instance of the terminal.

  • 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

CommandFunction
lsList 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.
UsageResult
mkdir folder1 folder2This command will create two folders, folder1 and folder2 in current directory.
UsageResult
cd ~This will take to to /home/ directory. In UNIX, tilde ~ is used to represent home directory.
cd ~/catkin_wsThis will take you inside a folder named catkin_ws in home directory
UsageResult
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.
CommandFunction
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.txt with 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.

  • man stands for manual.

    Terminal window
    man which
    man cat
    man find
    man grep
    man man