0% found this document useful (0 votes)
19 views14 pages

Linux Basics Part 1

Uploaded by

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

Linux Basics Part 1

Uploaded by

Irshath Ahamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

30 USEFUL

LINUX
COMMANDS

WITH EXAMPLES FOR


BEGINNERS, PART 1

1
by: https://www.linkedin.com/in/natalia-szczepanek/
LIST OF COMMANDS:
• cd • rm • chmod

• cat • touch • wget

• echo • find • sudo

• man • less • alias

• ls • tar • passwd

• pwd • grep • ssh

• mkdir • head • uniq

• tee • tail • sed

• cp • diff • top/htop

• mv • sort • history

2
W H AT I S A N D W H Y L I N U X ?
• Open Source Operating System (OS)

• Eagerly chosen by programmers. Why?


– It’s free
– More secure, it will protect your systems from trojans, viruses, adware etc.
– Easy to customize
– Variety of distribution: Ubuntu, Fedora, Deepin and many more…

• Linux is heavily documented

• Over 1000 commands, but I will present you 30 the most common in daily basis

• I highly recommend to learn at least basics of it, your life will be easier and you’ll be
able to automate a lot of tasks!
3
cd DIRECTORY
• Change directory from your current position

• Probably the most common command in linux

• You can pass DIRECTORY as relative or absolute path


– cd ~/absolute/path/to/Directory
– cd relative/path/to/Directory
– cd Directory

• cd ~ move to home directory (the same behaviour as cd alone)

• cd ../ move one directory up, can be used multiple time, for example cd ../../../
• cd- move to previously used directory

4
cat [OPTION]… FILE/S…
• Display content of file/s on the standard output

• Possible to display a content of one, multiple file and to concatenate content of


different files together using `>` and `>>` operators

• Examples:

– cat file.txt : display content of file.txt in the terminal


– cat file1.txt file2.txt : display content of both, first file1.txt and second file2.txt
– cat file1.txt file2.txt > combined_files.txt : concatenate two files and save it
as a new file called combined_files.txt with `>` operator, which is used for output redirection
– cat additional.txt >> existing.txt : add additional.txt content at the end of
existing.txt file, `>>` operator is used for appending output
5
echo LONG-OPTION
• Display text or variables as output, it is commonly used in shell scripts

• It is often used in shell scripting to display messages, debug scripts, or generate dynamic
output
• Examples:
– echo "Hello, world!” : print “Hello, world” in the terminal
– name="John”
echo "My name is $name” : print “My name is John” in the terminal
– echo "This is a new line.\nThis is a tab:\t\tAnd this is a backslash: \\”

• The use of escape sequences such as \n and \t with the echo command is necessary to format
and control the output by inserting new lines, tabs, and other special characters for improved
readability and presentation.

6
man COMMAND
• man is an interface to the on-line reference manuals, it is used to display the manual
pages (documentation) for various commands, programs, and system functions

• It provides detailed information about command usage, options, syntax, and examples

• For example:

– man find : display manual page for the `find` command

• Using the man command is a great way to explore and learn about various commands,
functions, and system features available in Linux, providing you with detailed
documentation to understand their usage and options thoroughly.

7
ls [OPTION]… DIRECTORY/IES
• List files and directories on current or given directory

• The second most known command J

• useful flags:

– ls –a list all files including hidden files


– ls -l list with long format
– ls –R recursively list subdirectories

• ls path/to/Directory list files in given path

• ls path/to/Directory1 path/to/Directory2 list files in given directories

8
pwd
• find the path to current working directory

• useful inside scripts to specify absolute path

• for example:

– pwd print current location


– echo "Your current location is: $(pwd)” to print current location
– location=$($pwd) to store path to current location

9
mkdir [OPTION]… DIRECTORY/IES…
• Make directories much faster than with manual clicking

• If you want to create multiple directories at once, just separate their names with space

• Useful flags:

– -v : prints a message for each created directory


– -p : create intermediate directories as required, without this flag all intermediate directories need to
exist already

• For example:
– mkdir new_directory creates a directory called “new_directory”
– mkdir –p new/intermediate/dirs will create 3 new directories if none of them already exist

10
tee [OPTION]… FILE/S…
• tee command takes the standard input, displays the
output and also saves it to one or more files
• tee can be used to replace and to add content to
the file, if file doesn’t exist – it will be created
• useful flags:
– -a : it appends the output to the files rather than
overwriting them

• very useful command inside scripts, for


example when you want to show the
output of the script and save it as log file
11
c p [ O P T I O N ] … S O U R C E … D E ST I N AT I O N
• Copy files or directories with their content wherever you want

• Useful flags:
– -v : cause cp to be verbose, showing files as they are copied.
– -r (or –R) : copy directory content recursively

• For example:

– cp file.txt /home/files – copy file.txt and paste it to /home/files directory


– cp file1.txt file2.txt file3.txt /home/files - copy file1,2,3 to /home/files/ directory
– cp file1.txt file2.txt copy file1.txt and create a copy file2.txt in the same directory
– cp –R /home/files/photos /home/files/destination copy photos directory to destination dir

12
m v [ O P T I O N ] … S O U R C E … D E ST I N AT I O N
• Rename or move files and directories with their content from one destination to another

• Useful flags:
– -i : interactive mode, which prompts for confirmation before overwriting existing files

• Examples:

– mv file.txt renamed_file.txt rename file.txt to renamed_file.txt


– mv file.txt /home/files/ move file.txt to files directory
– mv file1.txt file2.txt /home/files/ move multiple files silmutaneously

13
T H E E N D O F PA RT 1

T H A N K YO U

14

You might also like