0% found this document useful (0 votes)
9 views5 pages

Essential Linux Commands Guide

The document outlines basic commands and functionalities of the Linux operating system, including memory management, process handling, file system operations, and hardware interactions. It provides examples of commonly used commands such as 'mkdir', 'rm', 'cp', 'mv', 'grep', and 'ssh', along with their syntax and usage. Additionally, it covers topics like process management, permissions, and remote connectivity in Linux.

Uploaded by

Hyder Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Essential Linux Commands Guide

The document outlines basic commands and functionalities of the Linux operating system, including memory management, process handling, file system operations, and hardware interactions. It provides examples of commonly used commands such as 'mkdir', 'rm', 'cp', 'mv', 'grep', and 'ssh', along with their syntax and usage. Additionally, it covers topics like process management, permissions, and remote connectivity in Linux.

Uploaded by

Hyder Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Basic Commanda:

there 4 main functions:

1)memory managemet
2)procees
3)file sysytem
4)Hardware

Linux is a multi user and multi tasking OS.

echo $SHELL -->to know which shell we are in


grep "Hyder" etc/passwd -->another command

bin ->bin directory contains all binar files


boot ->contains boot related files

pwd -> present working directory


ls - long listing files

man - gives details of command


ex : man ls

creating a folder(directory)
mkdir
syntax:
mkdir foldername
ex:
mkdir training
go into the folder
cd (change directory/folder)
ex:
cd training

remove a file
rm (remove)
ex:
rm display1.c
copy the file into another file
cp
Syntax:
cp source destination
ex:
cp display.c display1.c
this command will keep the source and copy into another file,
source and destination both exists.

mv (move)
syntax:
mv source destination
this command will rename source file to destination, hence
after this command execution, source will not exists

chmod -> to change permission


3. change the permissions like
chmod 777 [Link]
chown -->used to change ownership
sudo chwon Hyder:Hyder training

find:

search for [Link] in my current directory/any other directories


Command: find
find command will search for a file

command:
find . -name [Link]

grep:
search for a string in a folder/file:
ex:
search for "main" in my current folder
command : grep
ex:
grep "main" * (this command will search for a string "main" in all the files
in the current folder)

grep "main" [Link]

Display the file names that matches the pattern : We can just display the files
that contains the given string/pattern.
$grep -l "unix" *
Show line number while displaying the output using grep -n : To show the line
number of file with the line matched.
$ grep -n "unix" [Link]

grep -R "main" * it will search recursively in all directory

grep -i "Main" * (this command will search for a string "Main" in all the files in
the current folder after ignoring the case sensitivity)

egrep : used to serach more than 1 string at a time


egrep "key1|key"

df -->
to check for free disk space in all disks : df

du ->to check for space in pwd.

ps -> it will display the processes that are running

ps -aux ->it will dispaly the process of particular user


x=user name

ps - (Process Status) - It reports a snapshot of current processes.


top (Table Of Processes) - is a task manager program displays information about CPU
and memory utilization.

kill -> to kill the running processes


ex:
kill -9 processid
kill -9 213

kill -15 is the safe and correct way of terminating a process. It's equivalent to
safely shutting down a computer.

kill -9 is the unsafe way of brutally murdering a process.

cat --> to show content of particualr file

cat [Link]

head:
it will print from top
cat [Link] | head -n 2 (this command will print first 2 lines from the
[Link] file)

tail command:
tail -n 1 [Link]
cat [Link] | tail -n 1
this command will print the last line of the [Link] file

diff -->knows the diffrent of 2 files

VIM---

Vi editor

vi commands
vi is a editor in unix/linux
this editor will work in 2 modes:
1. insertion mode
2. esc mode

1. insertion mode: (i)


if you want to edit/type then we need to use this mode
2. esc mode (esc button)
Where you can execute some commands
-> delete a character (x)
-> delete a word (dw)
-> delete a line (dd)
-> delete multiple line (5 dd or 10 dd or 20dd)
-> go to the begining of the file (:1)
-> go to the end of the file (:$)
-> set nu (setting line numbers)
-> save a file (:w)
-> save and quit (:wq!)

yy ->to copy full line and store in buffer and press key to paste it

10 yy --> to copy 10 lines

/ ->to search string from top


/hyder

? -->to search from bottom


?hyder
to replace string

For example, to search for the first occurrence of the string ‘foo’ in the current
line and replace it with ‘bar’, you would use:
:s/foo/bar/

To replace all occurrences of the search pattern in the current line, add the g
flag:
:s/foo/bar/g

If you want to search and replace the pattern in the entire file, use the
percentage character % as a range.
This character indicates a range from the first to the last line of the file:
:%s/foo/bar/g

:set nu -> to set line number

Linux Remote connectivtity:

ssh
scp
telnet
putty

which command is used to access system from another linux server?(to connect
remotley)
ssh
defual port is 22
ssh (Secure shell)bcs communication between host and client in encrypted format.

we can also use telnet command but it's not secures but ssh is secured.
defual port is 23

scp command is used to copy file.

Linux OS.

Shell it's a nothing but interface between user and kernal


linux provide lot's of command for process, file.

System call is we are going to get the service from [Link] call is a
gateway get enter into kernal.
each module present in kernal there will be system call , for process, file ,
device management etc.

process memory map


->stack
->heap
->data
->text

process states.
start -> ready ->running ->exit

when we run program in linux os it create a child process.

inter process communication(IPC)


->message passing
-> shared memory
-> signal

Common questions

Powered by AI

In Linux, the '/bin' directory is significant because it contains essential binary executables needed for booting and running the system, accessible for both system and user processes. On the other hand, '/boot' contains boot loader files needed to start the Linux operating system. Both directories play crucial roles in system functionality and stability.

File permissions in Linux can be modified using the 'chmod' command. Setting 'chmod 777' on a file makes it readable, writable, and executable by all users, which can pose security risks by allowing any user to alter or execute the file. Such broad permissions should be used cautiously and usually only in controlled environments.

The command used to recursively search for a string ignoring case sensitivity in all files and directories in Linux is 'grep -Ri "string" *'. This method is used because it allows searching within entire directories and subdirectories for a string while ignoring case differences, making it thorough and flexible for varying text case scenarios.

The Vi editor in Linux is a text editor known for its efficiency and control over text editing. It operates in two main modes: Insertion mode, where text can be added or edited, and Esc mode, where commands for manipulating text (like deleting lines or saving files) are executed. This dual-mode operation allows for powerful text editing and customization under minimal keystrokes, benefiting advanced users seeking speed and precision.

'Kill -15' is a safer command used to terminate a process as it allows the process to shut down gracefully, similar to safely shutting down a computer. 'Kill -9', however, forcefully stops the process immediately without allowing it any cleanup, which might lead to data corruption or loss. 'Kill -15' is preferred in most cases unless the process is unresponsive, in which 'kill -9' might be the only option.

The 'grep' command significantly enhances file searching capabilities in Linux by allowing users to search for specific patterns within files. It offers advanced features like recursive search with '-R', case-insensitive search with '-i', and displaying line numbers with '-n', facilitating detailed and specific file queries. This comprehensive searching makes it indispensable for developers and system administrators.

In Linux operating systems, system calls provide a gateway for user applications to request services from the kernel. Each module within the kernel has system calls for various operations like process, file, and device management. These calls enable inter-process communication and efficient resource management, significantly impacting system performance and capability. By acting as an interface between user space and kernel space, system calls maintain system security and stability.

SSH (Secure Shell) provides encrypted connections between the client and host, ensuring security during data transmission, and operates on default port 22. Telnet, though useful for remote connections, does not encrypt data, making it insecure and prone to interception, and uses port 23. SSH is generally preferred for secure remote access due to its strong encryption.

You can copy a file into another while retaining the original using the 'cp' command in Linux. The syntax is 'cp source destination'. For example, 'cp display.c display1.c' will copy the contents of 'display.c' to 'display1.c', leaving the original 'display.c' intact. This helps in creating backups or experimenting with copies without affecting the original files.

The command 'mkdir training' creates a new directory named 'training' in the Linux environment. Directory creation is important for file system organization as it allows users to categorize and manage files systematically, improving accessibility and maintenance of large systems by storing related data together.

You might also like