Basic linux Commands For Beginners

Basic Linux Commands For Beginnners

Directory Commands

Commands Operation
mkdir abc
Create directory named abc
mkdir -p abc
Create directory if it does not exist
mkdir -p abc/xy­z/123 
Create all direct­ories and subdir­ect­ories if they do not exist
pwd
Show the current directory
cd abc
Change to directory abc
cd ..
Change to the parent directory
cd ../xyz
Change to the sibling directory xyz
cd -
Change back to previous directory
ls
List files in directory
ls -la
List files, including dot-files, with extra info
ls -lhSr
List files in reverse size order; w/friendly size

 

File Operations

Commands Operation
touch file
update file last modified date; create file if not exists
cat file
output contents of file
less file
paged output contents of file
cp file1 file2
copy file1 to file2
mv file1 file2
mv file1 to file2
rm file
delete file
head -5 file
show the first 5 lines of file
tail -5 file
show the last 5 lines of file
tail -f file
show the last few lines of the file and follow output

 

Shell Shortcuts

Commands Operation
CTRL-c
Stop the current command
CTRL-a
Go to start of line
CTRL-e
Go to end of line
CTRL-r
Search command history
CTRL-l
Clear the screen
!!
Run last command
!abc
Run last command that starts with abc

 

Simple Regular Expres­sions

Commands Operation
.
match any character once
*
match the preceding character 0 or more times
+
match the preceding character 1 or more times
?
match the preceding character 0 or 1 time
()
group patterns
|
match the pattern on the left OR right
^
match the start of the line
$
match the end of the line

 

Shell Variables

Commands Operation
env
Show all enviro­nment variables
echo $ABC
Show a specific enviro­nment variables
ABC=123
Create a local variable
export ABC=123
Create a variable accessible by child processes
$NODE_ENV
Used node.js code; expects value to be production or anything else
$HOME
Home directory

2 thoughts on “Basic linux Commands For Beginners”

Leave a Comment