Shell
Shell
The shell is the thing that stares at you when you open up a terminal on your machine. It usually looks like
user@ntpl-lap-206 ~$
We type in commands and we get the output. A good shell environment, is configured for you, when you install the config files from neoito-hub.
Adding to $PATH
The $PATH
variable stores the list locations where the shell looks for binaries.
Do a $ which ls
. The output should be /bin/ls
. Do an $ echo $PATH
on
the terminal.
So, if we want to add binaries/executables in a particular folder
(example: /home/akts/Programs/mongodb/bin
),
to the $PATH
variable, execute
export PATH="$HOME/Programs/mongodb/bin:$PATH"
Environment Variables
To figure out what shell we're using, do a $ echo $SHELL
. If we're running
bash
, the file to set environment variables will the $HOME/.bash_profile
. For
zsh
, it'd be $HOME/.zprofile
Here's an excrept from a sample .bash_profile
file.
export GOPATH="$HOME/go"export GOROOT="$HOME/Programs/go"export PATH="$PATH:$GOROOT/bin"
CLI Cheatsheet
System information
# Display Linux system informationuname -a# Display kernel release informationuname -r# Display Linux system informationuname -a# Display kernel release informationuname -r# Show all network interfacesip a
Monitoring
# Display and manage the top processestop# Interactive process viewer (top alternative) - sudo apt install htophtop# Capture and display all packets on interface eth0tcpdump -i eth0# Monitor all traffic on port 80 ( HTTP )tcpdump -i eth0 'port 80'
User Management
# Add the akts account to the docker groupusermod -aG docker akts
File and directories
# List all files in a long listing (detailed) formatls -al# Display the present working directorypwd# Create a directorymkdir directory# Remove (delete) filerm file# Remove the directory and its contents recursivelyrm -r directory# Force removal of file without prompting for confirmationrm -f file# Forcefully remove directory recursivelyrm -rf directory# Copy file1 to file2cp file1 file2# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.cp -r source_directory destination# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2mv file1 file2# Create symbolic link to linknameln -s /path/to/file linkname# Create an empty file or update the access and modification times of file.touch file# View the contents of filecat file# Browse through a text fileless file# Display the first 10 lines of filehead file# Display the last 10 lines of filetail file# Display the last 10 lines of file and "follow" the file as it grows.tail -f file
Process Management
# Display your currently running processesps# Display all the currently running processes on the system.ps -ef# Display process information for processnameps -ef | grep processname# Display and manage the top processestop# Interactive process viewer (top alternative)htop# Kill process with process ID of pidkill pid# Kill all processes named processnamekillall processname# Start program in the backgroundprogram &# Display stopped or background jobsbg# Brings the most recent background job to foregroundfg# Brings job n to the foregroundfg n
Archiving
# Create tar named archive.tar containing directory.tar cf archive.tar directory# Extract the contents from archive.tar.tar xf archive.tar# Create a gzip compressed tar file name archive.tar.gz.tar czf archive.tar.gz directory# Extract a gzip compressed tar file.tar xzf archive.tar.gz# Create a tar file with bzip2 compressiontar cjf archive.tar.bz2 directory# Extract a bzip2 compressed tar file.tar xjf archive.tar.bz2
Installing packages
# Install software from source code.tar zxvf sourcecode.tar.gzcd sourcecode./configuremakemake install# For .deb files, use the dpkg tool with root privillegessudo dpkg -i file.deb
The above list is taken directly from lta.