0% found this document useful (0 votes)
18 views

Cli Commands

This document provides an overview of many common Linux command line interface (CLI) commands for navigating directories, viewing file contents and permissions, managing processes, users and groups, copying/moving files, searching for files and more. Key commands covered include pwd, cd, ls, cat, cp, mv, rm, mkdir, rmdir, touch, less, find, top, ps, kill, chmod, useradd, userdel, groupadd, df, du, free and man/help commands.

Uploaded by

yossi kisslasi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Cli Commands

This document provides an overview of many common Linux command line interface (CLI) commands for navigating directories, viewing file contents and permissions, managing processes, users and groups, copying/moving files, searching for files and more. Key commands covered include pwd, cd, ls, cat, cp, mv, rm, mkdir, rmdir, touch, less, find, top, ps, kill, chmod, useradd, userdel, groupadd, df, du, free and man/help commands.

Uploaded by

yossi kisslasi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Linux Cli commands

Navigating between Folders:


pwd – shows current directory Resources consumption display using top: Looking for commads using man:
cd – changing to desired directory i.e cd Desktop top – display memory cpu etc. Usage man command – displays command info
cd command alone relocates to home directory. S key – updates refresh time of data display(cpu usage etc.) man -k – short description of command
cd ~ shifting to Home/username Folder I key – filter idle processes-display only running processes keyword.
cd / (with a space before slash) cd to root directory k key – kill process by tpying PID and then ENTER twice
cd .. back to the former directory q key – quit top command screen
cd ../.. going back 2 directories

Displaying Folder Content: kill command:


ls – display current folder content pidof process name- displays the PID number
ls ~ - display home/username content kill 3286 – kills process with PID 3286
ls / - display root directory content kill -KILL 3294 – forces kill of this PID
ls .. - display content of one directory back kill -9 3294 - forces kill of this PID
ls ../.. - display content of 2 directories back ps -ux – displays current user processes
ls -l – displays content in a form of list specifying ps -aux – display all users processes
ls -al – same as -l with hidden file display ps -U username – display username running processes
ls -R – displays all content recursively ps -C process name – display all instances of this process
premissions,creator,owner,date and time of creations,file type.
ls -lS – same as ls -l but sorted. echo command:
ls -d */ - displaying only directories. echo – prints all chars after the word echo on the screen
** if dir name consists of 2 words or more creating variable – myvar=”Mark” -create myvar
use double quotes as: ls -lS “my dir” echo $myvar wil print Mark word
echo -e ‘some \n text’ - prints some and next line text
Displaying/printing Files content: -e option stands for escape
cat – displaying/printing file content
cat File.txt – enables writing to File.txt File premission and chmod command:
to terminate writing use ctrl + d chmod – change premissions of user u
cat file1.txt file2.txt -disply the files consecutivly group g and others o
cat -b file.txt – adds numbers to non blank rows r – read w – write x - execute
cat -n – adds numbers to all lines chmod u+rwx file.txt – enables rwx premission to file.txt
cat -s – diminishes all blank lines to one line chmod ug=rwx file.txt – sets premission of user to rwx
cat -E – adds $ sign at the end of each row chmod a-rwx file – cancels rwx premission to all users
chmod u+rw,g=wx,o+r file
Redirection of output to a file:
cat > out.txt – redirect written words to out.txt (ctrl +d to terminate) Directory premission using chmod:
cat >> out.txt – enables to write a new attached input to out.txt same as in files
cat file1.txt file2.txt > out.txt – concatnate file1 to the end of file2 disabling write premission adds lock symbol to the folder
and saves to out.txt and prevents adding files for instance
cat file1.txt >>file2.txt – same as upper example only saves to file2. Substracting read premission prevents content display of the folder

Creating Directories using mkdir: which command:


mkdir Folder– create a new dir named Folder which – dispaly PATH of specific command
mkdir -p – creates nested directories i.e name/mark which bash – dispalys the path/location of bash
mkdir -p names/{john,dude,mark} – creates parent dir consists whatis – displays short description of command
john dude and mark folders
Adding user using useradd:
Removing directory using rmdir: useradd mark -m -s bin/bash -g users -c “my comment” (dont forget to use sudo)
rmdir Folder – remove empty folder directory m for creating home dir
rmdir -p a/b/c/d – removes all empty dir and sub dirs(deletes all) s the current shell
(without -p flag removes only top level dir d) g – the specific group
rmdir -pv – removes all empty directories and display removal process c – comment for user
passwd – enables to add password for the user
Removing Directories and files using rm;
rm – deletes files and directories according to option flag removing users using userdel:
rm -r – removes recursively all directories and file ls home – to see current users
sudo userdel mark – deletes user mark but not his home dir
Copying Files using cp: sudo userdel -r mark – erases home dir also
cp file1.txt file2.txt – copys file1 content to file2
(if file2 doesn’t exist it creates it) groups and adding groups using groupadd:
cp file.txt dir1 – copy file1 to dir1 group – display the groups of the current user
cp file1.txt file2.txt dir1 – copys the 2 files to dir1 cat /etc/group/ - dispaly all groups of the O.S
cp -i file1 file2 dir1 – interactive (-i) copy of 2 files to dir1 sudo groupadd java – adding java to /cat/group
(asks for premission i.e if file1 already exists) sudo groupdel java – removes java grpoup
cp ../file1 ../file2 . - copy upper folder file1 and file2 to current sudo gpasswd -a yosikiss java – adds java to yosikiss group
directory the dot after file2 denoting current directory -d flag removes java from yosikiss group
cp -R dir1 dir3 – cp dir1 and it’s content to dir3
(in case dir3 exsists , if not copys only content) Viewing resources using du df and free:
df – display amount of resources used/unused by O.S
Moving Files and Folders using mv: df -h – readable versin of df
mv options source destination du – estimates and display disk space used by files
mv file1.txt file2.txt – changes file1 name to file2.txt and du -h – human readable for du
copys the content du -sh – summary of diskspace
mv file1.txt dir1 – moves file1.txt to dir1 free – displays the total free and used memory in the system
free -g – display data in gigabytes
Navigating through a text file using less: - k – for kilobytes
less file.txt – display file.txt -m – for megabytes
up and down arrow keys to move up/down -b - for bytes
space – moving page by page down
b key – moving page by page up running scripts /files using watch command:
shift g- moving to the end of file (like END key) watch – updating time intervals of current command
g key – moves u t the top of the file watch -n 1 free -m – display free resources on intervals of 1 sec
/book - enables search for the word “book” top to bottom ctrl + c – exiting watch command
(n to the next occourence of the word)
?book – enables search for the word “book” bottom to top Viewing files using head and tail: (for log files particulary)
q- quit less command head- display upper part of the file
tail- displays bottom part of the file
Creating new empty file using touch: head -n 3 file.txt – displays first 3 lines of file.txt
touch file.txt – creating new empty file.txt tail -3 file.txt – dispalys last 3 lines of file.txt
(if file exists updates timetamp of the file) tail -f file.txt – displays file.txt and follows input insertion and updates it.
head/tail dmseg kill.log - displays the files sequently
Linux Cli commands
looking for files using find command:
find /dir -name file.txt – will look for file .txt
in directory dir (-name option specify to look by name) ip config using ifconfig:
find home/yosikiss/ -name word.* - will look for all files ifconfig – displays all devices connections parallel to ipconfig
named word ignoring file type in home/yosikiss lo – specifys loopback connection for testing
find ~/ -name file1* - will search for all files named file1 wlp2s0 – wireless lan connection
find ~/ -mtime 1 – dsplays all file created 1 day ago ifconfig device – dispalys this device connection
(or + for future files) ifconfig eth0 down/up – turning this device/connection off/on.

Displaying word/character count using wc command: Compressing/extracting files using tar:


wc text.txt – displays no. Of lines, no. Of word, no. Of chars tar -cvf file.tar File – file.tar the name of the file File for folder
-c – displays chars only c for create
-l – dispalys lines only v for verbose
-w – displays oly words f for file
-L – displays number of chars of the longest line. tar -xvf file.tar – extracts file.tar , x for extraction
for .gz files you should add z flag
Installing/removing/updtating usin apt-get: tar -czvf file.txt File – z option for tar.gz files
**remember to use sudo
sudo apt-get install java printing document text using grep:
to check if certain package is installed grep – global regular expression print
you can use java-version grep “word to search” filename
sudo apt-get remove --purge java – removes package dependencies i – flag for non case sensitive
**remove/autoremove/install/update/upgrade n – flag for stating line number
cat etc/apt/sources.list – for apt sources. The expression can be more than one word
you can look for the expression in multipule files
Shell scripting: using astrisk states to look for word in all files.
cat /etc/shells – display shells O.S supports. grep -n “something good” file1 file2 file3
Which bash – location of current shell grep -n “something” *
# - used to write comments grep -v “something” file.txt – prints all lines that doesn’t contains “something”
name=Mark – creates variable name (to use it $name)
echo $name will print Mark. Network statistics using netstat:
Read -p ‘username: ‘ user_var – enables to read input and netstat -a – display all networking protocols running.
display it in the same line. netstat -a | less – display info in a shell size box using less
read -sp ‘username: ‘ user_var – silent print of input. -t – for tcp connection
Read -a names – read names and store it in an array. -u – for udp
echo “names: ${names[0]}, ${names[1]}” -l – for listening
echo -e – enables printing backslash chars.e -s – for statistics
name = (“$@”) -p – pid of connection
-x – for unix connections
-n – displays numric ports
-ie – i for interface , e for extended mode. Same as ifconfig
netstat -an | grep “:80’ - looks for ports 80

installing chrome browser:


adding -- no-sandbox to / opt / google / chrome /google-chrome

You might also like