Here’s a list of useful tools and commands that are required often for using Linux as a daily driver or even only for development.
This article will cover commands from bash, zsh, and fish since they are mostly compatible.
Concepts: Environment variables
, Aliasing
, Path
Built in commands: set(fish)
, cd
, pwd
, ls
, mkdir
, touch
, cat
, echo
, rm
, cp
, mv
, grep
, wget
, tar
Installable commands: nano
, mousepad
Before starting with commands here are some core concepts you should be aware of:
~
in a path represents the home directory (eg: /home/username/
)
/
represents the root directory
Values starting with a $
denote an environment variable. For example, $HOME
returns the path to your home directory. If the environment variable is not found an empty string is returned.
sarthak@sarthak ~> echo $HOME
/home/sarthak
sarthak@sarthak ~> echo $THIS_ENV_DONT_EXIST
sarthak@sarthak ~>
There might be some differences between syntax patterns in different shells, in that case, alternatives will be used.
These are basic commands you should know to use the terminal efficiently.
Environment variables are used to store values for a process into the system, there are several Environment variables like PATH
, PWD
, USER
etc set up by the processes on the system. Here are some operations you can perform on them.
# reading a env variable
echo $HOME # prefixing the name with $
ENV_NAME="VALUE" # setting value for a session
# Example
sarthak@sarthak:~$ VAR2="sarthak in bash" # using bash
sarthak@sarthak:~$ echo $VAR1 $VAR2
sarthak in bash
sarthak@sarthak ~> set VAR1 "sarthak in fish" # using fish
sarthak@sarthak ~> echo $VAR1
sarthak in fish
You can create aliases for long commands using alias
command. These are useful when you need to repeat same task multiple times.
alias [ALIAS] [COMMAND]
Example
The path variable stores directory addresses where executable files are stored. These are stored in a single string seperated by a colons. You can access the path using the PATH
variable in the shell. Adding a path temporarily To add a path temporarily you can use the export
command in the active shell
export PATH=$PATH:/path/to/directory # for bash and zsh
fish_add_path /path/to/directory # for fish
This will add the PATH to the path variable for current shell session. Adding a path permanently You need to edit your RC file which should be named after your shell ( .bashrc
, .zshrc
) to execute the commands from above. For fish shell you need to add the set command in ~/.config/fish/config.fish
cd
command is used to move from one directory to another. The syntax for the command iscd [DIRECTORY] # where directory is the path of the directory to navigate to
cd .. # to navigate to the parent directory of your current
# you can also navigate to other dir in the parent dir
cd ../other_directory_in_parent_directory
cd ~ # for the home directory
cd / # for the root directory
# exclusive to fish, you can type in the directory path directly
directory/
# example
sarthak@sarthak ~/p/codeforces (main)> pwd
/home/sarthak/projects/codeforces
ls [DIR_NAME=pwd] # current directory is listed by default
ls -R # shows files and folders inside the dir recusively
# you don't want to use the -R tag most of the times.
mkdir
command is used to m
ak
e dir
ectories in the current working directory. Command syntax:mkdir [DIRECTORY_NAME] # creates a directory with the name provided
# if the directory is a subdirectory and the parent dir does not exist
mkdir -p [DIRECTORY_PATH]
# example
mkdir hello/world # will error since dir hello does not exist
mkdir -p hello/world # will create hello dir with world dir inside it
touch hello.txt # creates a new file called hello.txt
cat
inate the contents of file(s) and display them. Command Syntax:cat [FILE(s)]
# example
cat file1.txt file2.txt
echo "text to display in shell"
echo "text to display in file" > filename
# Example
sarthak@sarthak ~> echo "import hello" > main.py
sarthak@sarthak ~> cat main.py
import hello
rm
command is used to r
em
ove files or dirs specified in the argument. Some useful flags for this command are: r
: recursively remove items from the directoryf
: ignore files that do not exist without any promptsCommand Syntax:
rm <flags> [TARGET]
# Example
rm hello.txt # will remove the hello.txt file
rm -rf src/
# will remove all the files and dirs inside the src dir and delete it
c
op
y of a file. Command syntax:cp [SOURCE_FILE] [TARGET_FILE] # target file created if doesn't exist
# Example
sarthak@sarthak ~> cat hello.py
import hello
sarthak@sarthak ~> cp hello.py test.py
sarthak@sarthak ~> cat test.py
import hello
m
ov
e command is used to move the file from one location to another. It can also be used to rename the file.mv [FILE] [TARGET] # target can be a directory or a file name
# Example
sarthak@sarthak ~> mkdir test_dir
# moving to a new directory
sarthak@sarthak ~> mv hello.py test_dir/
sarthak@sarthak ~> cat test_dir/hello.py
import hello
# renaming the file
sarthak@sarthak ~> mv test_dir/hello.py test_dir/renamed_file.py
sarthak@sarthak ~> cat test_dir/renamed_file.py
import hello
grep <tags> [STR_TO_SEARCH_FOR] [FILENAME]
# Example
sarthak@sarthak ~ [1]> grep "py" space/src/lib.rs
use pyo3::prelude::*;
#[pyfunction]
#[pymodule(name="space")]
m.add_function(wrap_pyfunction!(test_function, m)?)?;
# For better output use the --color and -n tags
# it will highlight the output and add line numbers to the matches
wget <-c> [URL] # the c tag is used to establish a continous download
# Example
sarthak@sarthak ~> wget -c https://bootstrap.pypa.io/get-pip.py
--2024-08-24 08:01:29-- https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.156.175, 2a04:4e42:25::175
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.156.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2266755 (2.2M) [text/x-python]
Saving to: ‘get-pip.py’
get-pip.py 100%[=================================================>] 2.16M 10.3MB/s in 0.2s
2024-08-24 08:01:30 (10.3 MB/s) - ‘get-pip.py’ saved [2266755/2266755]
Text editing tools like nano
and vim
come pre installed on most linux distributions. You can use nano
for basic text editing inside the terminal. Usage: nano [FILENAME]
Alternatively you can use mousepad
for GUI based editing. Usage: mousepad [FILENAME]
The tar
command is used to work with tar.gz
format which is mostly used in linux OS(s). Usage: tar [options] [archive-file]
You can use this command to unarchive files.
tar -cvzf [archive].tar.gz [FOLDER NAME]
These are the commands I use for development using Ubuntu(WSL) and Arch(Bare Metal) as a daily driver. Fell free to comment for improvements and other relevant useful information that can be added 😄.