top of page
  • ratneshlpatel

SHORT CUT KEYS FOR Linux



INTRODUCTION

An operating system is responsible for directly managing a system’s hardware resources like CPU, memory and storage. Linux is one of the most widely-used open-source operating system. It is a bundle of tools, programs and services along with the lInux kernel which provides a fully functional operating system. Linux can be differentiated from other operating systems in many ways. Firstly, Linux is an open-source software. Different Linux distributions come with different software options. Each distribution has its own approach on desktop interfaces. As such, users have the ability to choose core components such as graphics, user-interface, etc., as per their preference.

Here, we have attempted to cover the widely used Linux commands. With new Linux distributions, there are chances of a few commands getting deprecated. So, make sure you keep up with the new releases, their new additions and commands which are rendered deprecated.


1. GENERAL SHELL COMMANDS

COMMAND

SYNTAX

​alias

alias home=’cd home/hackr/public_html’

set-x

set [--aefhkntuvx[argument]], where a, e, f, h, k, n, t, u, v, x are the different options that can be used with this command.

\

script

​​script [options] [file]

~

reset

​reset [terminal] There are a number of options that can be used with reset to customize the output.

​exit

exit

logout

logout

echo

echo “text” echo rm -R

history

history n – Lists the last n number of commands !<command_name> will list the last command typed with <command_name>

2. COMBINATION KEYS

CTRL+D

​It is an end-of-file key combination and can be used to log out of any terminal.

CTRL+Z

This key combination is used to stop a process. Also, it can be used to run a background process.

CTRL+A | CTRL+E

These key combinations are used to navigate to the start and the end of a line on the command line.

CTRL+K

​Used to delete what is in front of the cursor.

CTRL+Y

​Pastes the last text that was deleted.

CTRL+W

​Cuts or deletes the entire line that has been typed.

SCREEN

This command is used to switch between multiple virtual terminals. It is mainly useful with remote login. By default, you start with one terminal. CTRL + A & C can be used to create a new virtual terminal.

​CTRL+N

​CTRL + N is used to go to the next virtual terminal

CTRL+P

CTRL + P is used to go to the previous virtual terminal.

CTRL+C

This combination key breaks/kills a process that is running on the terminal.

CTRL+ALT+DEL

This key combination can be used from a terminal to reboot or shutdown. Here the user does not have to be logged in.

3. HELP

man

Displays the summary of a program from an online manual.

​man <program_name> man -f: Lists the details associated with the command. man -K <keyword> : searches the manual for the specified keyword.

info

Gives a more detailed hyper-text manual on a particular command.

info <program_name>

what's

Describes a program in one-line.

whatis <program_name>

apropos

It searches the database for strings.

apropos <string>

4. INPUT/OUTPUT


>

Send information to a file.

cat file1 file2 > file1_and2.txt

<

Inserts information into a text file. It is generally used with other commands that are used to extract information through standard input.

​Ex: tr ‘[A-Z]’ ‘[a-z]’ <filename.txt >newfilename.txt

>>

Appends information at the end of file. It creates the file if it does not exist.

<<

It is mainly used in shell scripting. It is also used with command that are used to extract information.

2>

​Used for redirecting error output.

|

​It sends the output of one command as an input for another command.

Tee

Sends the output of a file to the standard output.

​tee -options file_name.txt

&>

Used to redirect output to a specific location

​make &> /dev/null

COMMAND

''

Used to direct the output of the second command to the first command.

1st_command `2nd_command -options`

$

Used to direct the output of the second command to the first command.

1s​ t​_command $(2n​ d​ Command)

|

​Used to direct the output of the second command to the first command.

cat command1 | command2

​MULTIPLE COMMAND

&&

​Runs the 2n​ d​ command only if the 1s​ t​ command runs successfully.

1s​ t​command && 2​nd​ Command

||

Runs the 2n​ d​ command only if the 2n​ d​ command does not run successfully.

1s​ t​ Command || 2n​ d​ Command

;

2n​ d​ Command is executed after the 1s​ t Command is executed.

1s​ t​ Command; 2n​ d​ Command


5. FILE MANAGEMENT & FILE HANDLING

access

​This command is used to check if a program

has access to a specified file or whether the

file exists or not.

access (const char *path, int mode)

awk

​This command is a scripting language used for

manipulating data and generating reports.

awk -options filename.txt

batch

​This command is used to read commands from

the standard input or a file and execute them

when permitted by system load levels.

batch

bc

​Used for command line calculator

bc -options file_name.txt

cd

​Change Directory.

Used to go to the previous directory.

Can be used with the absolute path or the

relative path.

​cd cd pathname

Is

​Lists files and directories. ​Does not list hidden files or directories

​ls -options, where options can be l, a, d, F, S, R.

pwd

Print the current working directory

pwd

tree

​Lists all files and directory recursively.

tree

find

​This is used to search for files on a filesystem.

The search can be customized with many

options.

​find / -name file

Slocate

​Lists all the files in the system that match the

specified pattern

slocate string

Whereis

​It locates the source, binary and the manual

page for a particular program.

​whereis program_name

which

​It only looks for the executable program

which program_name

mkdir

​Make Directory.

​mkdir Dir1 mkdir -p /home/dir1/dir2/dir3 This command creates dir1, dir2 and dir3 as it goes.

rm

​Removes or delete a file or a directory

rm -options file_or_folder

rmdir

​Removes an empty directory.

rmdir directory

mv

​Used to move a file or directory to another

location. It can also be used to rename a file or

a directory.

mv existing_file/folder new_location

cp

​Copy a file

cp -options file_to_be_copied new_location

In

​Used to create a link to a file. Links can be

hard-links or symbolic links. A hard-link is a

reference to a file while a symbolic-link is

similar to a shortcut link.

ln target_name link_name ln -s target_name link_name

shred

​Overwrites a file and removes it in order to

make it irretrievable by the software or

hardware.

shred -n 2 -z -v /dev/hda1

du

​It is used to display information about the file

size. It can also be used on directories, which

then displays the information about all the

size of all the files and subdirectories.

du -options file_name/directory_name

file

​It shows the type of a particular file. It displays

the inode number, creation data/access date

along with some advanced options.

file file_name

stat

​Give detailed information about a file.

stat file

dd

​Used to create copies of disks, perform

conversions on files and very the block size

while writing the file.

dd operand dd option dd inputfile_path outputfile_path

touch

​Used to create empty files. It is also used to

increase the timestamps on the file.

touch -t 09072019 filename.txt

split

​It is used to split files into several small files.

split -options filename split -b xx – splits the file into xx bytes, split -k xx – splits the file into xx kilobytes split -m xx – splits the file into xx megabytes

rename

​It is used to rename files as per regular

expression.

rename -options file_name

6. SYSTEM INFORMATION


time

​It is a utility that measures the time taken by a program to execute.

​time program_name options

/proc

The files under /proc displays system information.​

​cat /proc/cpuinfo – displays information about the CPU.

dmseg

This command is used to print the contents of the bootup messages displayed by the kernel. This is particularly useful in debugging issues.

​dmseg

df

​Displays the information about the space on the mounted file-systems.

​df -options /dev/hdx

who

​Displays information about the logged in users including their login time.

who

w

​This command displays who are logged in into the system and the processes they are running.

​w

users

​This command prints the name of the currently logged in users.

​users

last

This command displays the time of the logged-out users. This also displays the information when the computer was rebooted.

​last

lastlog

Displays a list of the users and the time/day of their login.

lastlog

whoami

t tells the username of the logged in user.

whoami – it does not need or take any options.

free

Displays memory status. (Total, Used, Free, cached, Swap)

free -tm, where t displays the total statistics and m displays the space in megabytes.

uptime | w

​It displays how long the computer has been up and running. Additionally, it displays the number of users and the processor load.

uname

​It is used to display system information such as OS type, kernel version, etc.

​uname -options, where the options can be – a, n, m, s, r, p

xargs

​This command is used to run a command as many times as required.

​Ex: ls | xargs grep “search string” The various options that go with it are: - Nx, lx, p, t, i.

date

​It is used to display the system. It can also be used to set the date/time.

date -s hh:mm:ss

cal

This command displays the calendar of the current month.

cal -y – Displays the calendar of the specific year.

acpi

This command is used to display the battery status and other ACPI(Advanced Configuration and Power Information) related information.

acpi -options Using different options will give different system information.

acpi_available

​This command is used to test if the ACPI subsystem is available.

​acpi-available

aptitude

This command opens up a highly built-in interface to interact with the package manager of the machine.

7. SYSTEM MANAGEMENT


proc

This command gives information about the hard- drive.

cd /proc/ide0/had

fdisk

It gives information on any hard drives that is connected to the system and their partitions.

fdisk

shutdown now

​It starts the process of shut-down immediately. This command can also mean go to a single user mode. This command can also be used to shutdown a system at a particular time.

shutdown now

halt

​This command shuts down the system immediately.

​same as shutdown -h

reboot

​This command is used to reboot the computer immediately.

same as shutdown -r

ps

​This displays the list of processes running on the system. When used without any options, it lists the processes run by the current user in the controlling terminal.

​ps -aux: lists all processes run by all users.

pstree

​Lists all the processes in a tree structure.

​pstree -p: lists all processes along with their ID’s

pgrep

​This command is used for finding processes via keyword terms. Generally, this command returns only the PID no. It can be used to list process names or via usernames.

​pgrep

top

​This command is used to list process in the order of CPU usage. It has many additional options that go with it, which helps to get the desired result.

​top

kill

​This command is used to kill a process. It requires the pid or the id of the process.

​kill pid kill %id

killall

​This command is used to kill a process by its name.

​killall -v: will make the process report if the kill was successful. killall -i – will prompt the user to confirm before attempting the kill.

pkill

​This command is used to kill a process specified by a regular expression.

​pkill process_name pkill -u: is used to kill the processes of a certain user.

skill

​It is used to continue, kill, stop the process. The process can be specified via username, command name or process-id.

​Ex: skill -stop unauthorised_username

jobs

​It displays the list of currently running jobs in order of execution. This command is available only in bash, csh, ksh and tcsh shells.

​jobs [job_name]

bg

​It runs a process in the background. An & sign at the end of the command can also be used to run a job at the background.

​bg job_number bg job_name

fg

​This command is used to bring a process at the foreground. This will take over your current terminal.

​fg job_number fg job_id

nice

​This command is used to set the CPU priority for a process. In order to set a higher priority for a process, the user needs to be a root user. However, any user can lower the priority of a process.

​nice -20 <process_name>: sets the maximum priority nice 20 <process_name>:: sets the minimum priority

renice

​Changes the priority of an existing command.

snice

​Along with changing the priorities of a process, snice can also be used to stop, continue or kill a process.

​snice -upctvi, where u,p,c,t,v,I are all options that make snice perform differently.

service

​It allows to perform different tasks on services.

​service -sfR, where s, f, R are all different options that can be used with it.

autoconf

​This command is used in Linux to generate configuration scripts.

8. USER MANAGEMENT