Cheat sheet for Linux initialization

Cheat sheet for Linux initialization

Cheat sheet for Linux initialization

Linux initialization have hundreds of commands. There are easily over 1,000 distinct commands, even on a basic Linux server installation.

The fascinating thing is that only a tiny fraction of those commands are used by the majority of individuals. You may find a “cheat sheet” for Linux commands that categorizes some of the most used ones below.

This cheat sheet offers a broad overview; however, keep in mind that the init system and implementation might differ between Linux variants.

Here is a list of all the useful commands for Cheat sheet for Linux initialization.

For input or output, use the commands given below.

  • Echo

String values can be printed using it in the terminal.

Example

echo “Hello World” #Print with a new line
echo -n “Hello World” #Print without a newline
echo -e “Hello\tWorld” #Print with tab space

  • printf

Formatted string values can be printed using it in the terminal.

Example

printf “Hello World” #Print without a newline
printf “Hello World\n” #Print with a newline
printf “The price of the book is %0.2f\n” 56.856 #Print the formatted data

  • read

It is used to solicit user input.

Example

read variable #Take single input
read variable1, variable2, variable3 #Take multiple inputs
read – p “enter your name: ” variable #Take input with prompt
read – sp “enter password: ” variable #Take secret input
read – t 5 – p “Enter your pin : ” pin_number #Take input with a time limit
read – n 11 mobile #Take input of maximum length

  • pipe

It is used to move the output of one operation to the input of another. The pipe is represented by the symbol ‘|’.

Example

# The output of`echo` command will be sent as the input of the`wc` command
echo “Hello World” | wc –w

  • Redirection

After running the command, Linux uses redirection to modify the device’s standard input/output. Use the symbol “,” for input redirection, and “>,” for output redirection.

Example

ls – l > folderList.txt #Redirect output
ehco “test” 2 > error.txt #Redirect error into the file
ehco “test” 2 >& 1 error.txt #Redirect error into the file and the terminal
cat > myfile.txt < folderList.txt #Redirect input data from one file to another file

For System Information, use the commands given below.

  • Date

It is used to print the current date and time on the system in several different forms.

Example

date #Print current date and time without formatting
date +%m-%d-%Y #Print the current date
date +%H:%M:%S #Print the current time
date +”%A, %B %d,%Y” #Print the current date with weekday and month name

  • hostname

The hostname, domain, and IP address may all be checked or changed using it.

Example

hostname #Display the hostname
hostname -d #Display the domain name
hostname -I #Display the IP address
hostname -b new_hostname #Set the new hostname

  • uname

It is used to publish various hardware and operating system-related information.

Example

uname #Print the kernel name
uname –n #Print the hostname
uname –m #Print the hardware name
uname -o #Print the operating system name
uname –a #Print all information related to hardware and OS

  • vmstate

It is used to gather data on the CPU scheduling, block IO, processes, processes on the disc, and memory.

Example

vmstat –a #Display the active and inactive memory of the system
vmstat –f #Display the number of forks since boot
vmstat -s #Display event counter and memory statistics
vmstat -d #Display disk statistics

  • estate

It is used to record statistics for the input and output of the system’s devices and partitions. This command has to be run after the sysstat package has been installed.

Example

Iostat #Print all statistics and report
Iostat -c #Print the statistic information of CPU
Iostat -d #Print the device report
Iostat -x #Print the statistics information in detail
Iostat -k # Print the statistic in KB or MB
Iostat -p #Print the statistics information of block devices
Iostat -N #Print the statistics information of lvm2

  • Free

A thorough report of the system’s memory use is printed using it.

Example

free #Print the output in the default format
free -h #Print the output in human-readable format
free -b #Print the output in bytes
free -k #Print the output in KB
free -g #Print the output in GB

  • whoami

It is used to display the name of the user who is currently logged in.

Example

whoami #Print the logged-in user’s name

  • uptime

It is used to print details about the system’s overall running time.

Example

uptime #Print the uptime in the default format
uptime -p #Print the uptime in a pretty format
uptime –s #Print the time since the system is up

  • shutdown

The system can be restarted, shut off, or powered off from the terminal.

Example

shutdown #Shutdown normally
shutdown –h 0 #Shutdown immediately
shutdown –r #Shutdown and restart
shutdown –r now #Shutdown and restart immediately
shutdown –c #Shutdown can be canceled

  • reboot

With root privileges, from the terminal, it is used to reboot the system.

Example

sudo reboot #Reboot the system

For User Management, use the commands given below.

  • Adduser

In the Linux system, Adding a new user account is done using it. This command needs root privileges to be executed.

Examples

#Create a new user information in default location
sudo adduser username
#Create a new user information in the specified location
sudo adduser username –home /home/temp/

  • Deluser

The Linux user account can be deleted using it. You must have root privilege to run this command.

Examples:

sudo deluser username #Delete user
sudo deluser –remove-home username #Delete user with home directory
sudo deluser –force #Delete user forcefully
sudo deluser –backup-to /backupUser username #Delete user

  • usermod

It is used to change any existing Linux user’s information. To be executed, it needs root privilege.

Examples:

sudo usermod –login newUsername oldUsername #Change the username
sudo usermod –uid newID username #Change the ID of an existing user
sudo usermod –gid groupname username #Change the group name of an existing user

  • groupadd

It is utilized to establish new groups. To run this command, root privilege is required.

Examples:

#Create a new group
sudo groupadd groupname
#Create a group forcefully if it already exists
sudo groupadd –f groupname
#Create a new group with a particular group id
sudo groupadd -g 6723 groupname
#Create a new group by defining the range of group id
sudo groupadd -K GID_MIN=4000 -K GID_MAX=5000 groupname

  • Groupdel

An existing group can be deleted using it. To run this command, root privilege is required.

Examples:

sudo groupdel groupname #Delete the group name
sudo groupdel –f groupname #Delete the group forcefully

  • groupmod

It is used to change any existing group. To run this command, root privilege is required.

Examples:

sudo groupmod -n newGroupname Groupname #Change the group name
sudo groupmod -g 676 Groupname #Change the group id

  • last

It is used to publish details about a Linux user’s most recent login session.

Examples:

last #Print all last login session information
last username #Print the last login session information of a user
last -10 #Print the last 10 login session
last –p 2022-01-01 #Print the last login session information of a specific date

  • id

IT is used to check up information about the current user’s or another user’s username, group name, and server user ID.

Examples:

id #Print the ID and group information related to the current login user’s
id username #Print the ID and group information related to the particular user
id -u username #Print the user ID of the particular user
id -g username #Print the group ID of the particular user

  • groups

The present procedure, together with the primary and secondary group names for each login, are displayed in the absence of a username.

Examples:

Groups #Print the group information of the current login user
groups username #Print the group information of the specific user
groups username1 username2 #Print the group information of the multiple users

  • Passwd

Changes to the user’s password are made using it. Only the root user has access to changing any user’s password; all other users cannot.

Examples:

passwd #Change the password of the current login user
sudo passwd username #Change the password of any user with root privilege

  • sudo

It is used to execute restricted tasks with root capabilities both while logged in as root user and when not.

Examples:

sudo apt-get update #Update the current system
sudo -i #Login as the root user
sudo bash #Run bash as the root user
sudu !! #Execute the last command with the root privilege

  • su

Do this to switch from the current user to a different user.

Example:

su username #Switch to another user without changing the home directory
su -l username #Switch to another user by changing the current directory
su -p username #Switch to another user by preserving the environment variables

For Packages, use the commands given below.

  • apt

In the Linux operating system, It is used to manage, update, and install different packages. It needs root access rights.

Examples:

sudo apt update #Update the installed packages
sudo apt upgrade #Upgrade the installed packages
sudo apt upgrade packagename #Upgrade specific package

  • apt-get

When used in place of the ‘apt’ command, ‘apt-get’ functions similarly, but uses several commands differently.

Examples:

sudo apt-get update #Update the packages
sudo apt-get dist-upgrade #Upgrade the packages with full dependencies

  • dpkg

Debian packages and their dependencies may be installed, removed, managed, and queried using it. To utilize it, root privilege is required.

Examples:

#Install the Debian package
sudo dpkg –i debian_package_name
#Print installed packages related to nano editor
sudo dpkg -l ‘*nano*’
#Remove vim editor
sudo dpkg -r vim

For Disk Usage, use the commands given below.

  • du

Information about disc consumption is obtained using it.

Examples:

du #Print the disk usage information in the default format
du -h #Print the disk usage information in human-readable format
du -c #Print the disk usage information with total measurement value.
du -s #Print the summary of the disk usage information
du -a #Print disk usage information with the sizes of files and folders

df

It is used to output information about the file system’s utilized available disc space.

Examples:

df #Print the used and available disk space in the default format
df -h #Print the used and available disk space in human-readable format
df -T #Print the used and available disk space with file system type
df –total #Print the used and available disk space with total values
df -a #Print the used and available disk space with other information

fdisk

It is utilized to create or modify the partition tables on the hard drive.

Examples:

fdisk -l #Print partition table of all devices
fdisk /dev/sdb #Run fdisk for the specific device
fdisk -l /dev/sda #Print the partition table list of a device

mount

It’s used to mount the file system and removable storage in a certain place.

Examples:

sudo mount #Print all currently attached file system
sudo mount -t ext3 #Print the list of all ext3 file system
sudo mount /dev/sda1 /mnt/media #Mount a file system and a directory

unmount

It serves as a means of removing the device from the mounted file system.

Examples:

sudo umount ext3 #Unmount ext3 file system
sudo umount /dev/sdb1 #Unmount sdb1 device

For Process Management, use the commands given below.

ps

It is employed to gather data about the system’s operational procedures.

Examples:

ps #Print the process list of the current shell
ps -e #Print the list of all running process
ps -a #Print the list of the process that is not associated with the terminal
ps -T #Print the list of the process that is associated with the terminal

  • pgrep

Based on the given criteria, it is used to determine the process ID of the program that is currently running.

Examples:

pgrep bash #Print the process ID
pgrep ssh -l #Print the process name with the ID
pgrep -u root #Print the process list of a particular user

  • kill

It serves as a means of signal transmission to PID-defined processes. The process is ended by the default signal, SIGTERM.

Examples:

kill –l #Print the available kill signals
kill 5645 #Terminate the process based on ID
kill -1 9078 #Reload the process based on the ID
kill –n 15 7845 8756 #Terminate multiple processes

  • killall

Using the specified process name, it is used to forcefully end any running process.

Examples:

killall processname #Kill the process based on the name
killall -i processname #Ask permission before killing the process
killall –u username #Kill process based on the username

  • pkill

Used to send identifiers to the running application’s process based on the full or incomplete process name, username, or other attributes.

Examples:

pkill firfox #Terminate a particular process
pkill -i gedit #Terminate a process in a case-insensitive manner

  • fg

Used to bring the background work of the current shell to the fore.

Example:

fg %1 #Refer to the specific job number
fg %+ #Refer to the current job
fg %- #Refer to the previous job

  • bg

A halted background process is restarted using it.

Example:

bg %1 #Refer to the specific job number
bg %+ #Refer to the current job
bg %- #Refer to the previous job

For Scripting Tools, use the commands given below.

  • Sed

It is utilized for searching, find-replacement, and inserting and deleting data.

Example

#Replace the word, ‘World’ with the word ‘Everyone’
echo ‘Hello World’ | sed ‘s/World/Everyone/’
#Replace the word, ‘book’ with the word ‘e-book’
sed ‘s/book/e-book/g’ filename.txt
#Delete the 5th line of the file
sed ‘5d’ filename.txt

  • Awk

It is a computer language used to process and scan patterns to produce reports and change data.

Example:

awk ‘{print}’ filename.txt #Print the content of the file
awk ‘/Linux/ {print}’ filename.txt #Print those lines of the file that contains ‘Linux’
awk ‘{print $1,$4}’ filename.txt #Print the first and fourth columns of the file

  • sort

It is used to arrange the information in a file.

Example:

sort filename.txt #Sort the string data in ascending order
sort –r filename.txt #Sort the string data in descending order
sort -n file1.txt #Sort the numeric data in ascending order
sort -o output.txt filename.txt #Redirect the sorted output of filename.txt to output.txt

  • wc

A file’s or the standard input’s characters, words, and lines may all be counted with this tool.

Examples:

echo “Hello” | wc –c #Count the total characters of the string
wc –w filename.txt #Count the total words of a file
wc –l filename.txt #Count the total lines of a file

Final Words

Linux initialization are used for task scheduling, managing system services, configuring kernel parameters, and starting and stopping system services. They make ensure that all relevant services are launched as part of the starting process. These instructions can be used to increase system efficiency, automate processes, and guarantee dependable system operation.

Links

You can learn about linux more deeply by clicking the link below

https://linuxiron.com/what-is-linux-a-whole-introduction/

Links

Learn about the linux commands by clicking the links below

https://linuxiron.com/echo-command-in-linux/

https://linuxiron.com/how-to-use-nice-renice-commands-in-linux/

https://linuxiron.com/how-to-use-kill-commands-in-linux/

https://linuxiron.com/a-beginners-guide-to-htop-for-process-management/

https://linuxiron.com/15-useful-yum-commands-in-linux/

https://linuxiron.com/how-to-use-the-top-command-in-linux/

https://linuxiron.com/17-ps-command-to-monitor-linux-process-with-examples-linuxiron/

https://linuxiron.com/12-cat-commands-in-linux-with-examples/

https://linuxiron.com/archiving-and-compressing-files-and-directories-in-linux/

https://linuxiron.com/how-to-run-the-du-command-in-linux/

https://linuxiron.com/how-to-backup-and-restore-the-linux-system/

Q. How do I obtain a command list?

Type “help” and hit the Enter key. All of the commands that are accessible will be listed. The items are arranged in alphabetical order. You might need to scroll up to find the command you want because the list is typically bigger than the Command Prompt window.

Q. How do I view all commands in the terminal?

Simply press Tab twice (Tab Tab). If you want to see all available commands, you will be asked. A list will appear when you tap y. The same procedure can be used to view all available choices for each command.

Q. What does apt mean in Linux?

On Debian and Debian-based Linux versions, the Advanced Package Tool, or APT, is a free software user interface that controls program installation and removal. It works together with major libraries.

Q. What does cmd do?

The program Command Prompt simulates user input on Windows operating system text-based user interface screens by utilizing the Windows graphical user interface (UI). It can execute entered commands and carry out sophisticated administrative tasks.

Q. How does Linux’s sudo work?

With sudo, which can be either “super user do” or “substitute user do,” you can temporarily grant root access to your current user account. The word “su” is transient; this is not the case.

Leave a Comment

Your email address will not be published. Required fields are marked *