UNIxnkv

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

unUNIX

CTRL+ALT+T -->For Opening the Terminal

In ubuntu, we will call files as files only but the folder we will call as directory

pwd --> Present/Print Working Directory -->will return the current path u are on

ls-->list-->This will list down all the directory in the current path

● ls -ltr -->long List time reverse--> -->will return permission,timestamp and


directoryname
t means it will sort descendingly all in with order by time
r means it will sort descending all in the order by name of directory
together -ltr means it will first sort descending by time and after that it will sort reverse
that order
● ls -a-->it will show all the hidden directories
● ls -F--> will give / for all directories mentioned
One command; 2nd command ;3rd command

You can mention this in single line itself but the unix will execute them seperately

ls -al→ shows the space occupied for


du (disk usage)--> a→all, h→human readable format

DIRECTORY COMMANDS

Mkdir-->make directory

● mkdir directory_name ….-->mkdir one two three--> this will create one two three
as directories
● mkdir -p parent/child/Nkv--> -p -->parent directory-->it created subfolders
cd--> change directory

● cd /-->will go to direct root directory


● cd -->will go to home directory
rmdir-->remove directory

● rmdir directory_name-->rmdir one two three-->this will removes the


mentioned directory
● rm -r parent--> will remove subdirectories and files
● Incase u want to delete the rmdir u need to delete all inside files
FILE HANDLING COMMANDS

File creation command

Touch file_name-->touch sample.txt--> This will create a 0kb file

Touch .file_name-->touch .indict.txt-->this will create a hidden file

To View the content of file u can use vi editor

Vi file_name-->vi sample.txt--> this will open editor u edit also the content of file
Incase u enter any content in the file the size of file also increases accordingly

Important shortcuts for using vi Editor

Command mode(by default)--> you can issue command to editor to copy lines and move and
insert and delete

Insert Mode→ in this mode you can insert data into file (editing mode)

i→ to switch to into insert mode

To switch back to command mode from insert mode use ESC

To delete a character type x

To delete the entire line type dd

To copy a line use yy

To paste a line use p

Scroll up/down → CTRL+u or CTRL+d

:w → To save changes and save file on disk


:q → Quit Vim editor

:wq→ To save and quit file

/of → this commands makes to search of keyword in the file with highlighted the keyword

Cat(concatenate the file)

cat file_name--> it displays the content of the file

cat >file_name-->It will create that file and u will get next line for entering the content u want in
that file

cat >>sample1.txt -->Using this u can add more lines of contents to existing contents

Cp(COPY)
cp file_name directory_name-->Copy the file from one directory to another directory

cp file_name1 filename2-->copy the file content of filename1 to filename2 incase filename2 not
exists it will create the file

Cp -r <dir1> <dir2> <target_location>--> copy the directory from one location to another location

To know whether entered command was successful or not.

You can use command --> echo $? --> it will show the 0 if previous statement was successful
and any other number then it means command was unsuccessful.
Mv(Move)

Mv filename directory_name -->this will move the file from one directory to another

Mv filename1 filename2 -->this will rename the filename1 to filename2 in that same location
Mv directoryname1 directoryname2 -->this command will change the name of directory also
HEAD

Head filename-->head employees.csv--> This will print first 10 lines of file including the header
line also

head -n no.of.lines filename-->head -n 5 employees.csv -->It will print just first 5 lines including
the header line also

Head filename1 filename2-->head employees.csv departments.csv--> this will print both file
data file1 first 10 and file2 first 10 lines and separation between them is there filename will
mentioned
Head -v filename-->head -v employees.csv--> this prints the filename with content of the files

Head -c no.of.characters filename-->head -c 25 employees.csv-->this will print respective no.of


characters from the file

Head -q filename1 filename2 --> head -q employees.csv departments.csv--> this will print the
both the file contents but there wont be filename present of these
TAIL

tail has similar commands as the head

incase u want records from 201 to 203


Head -n 7 employees.csv | tail -n 3

| this means it will apply the after | pipe command before | results

Means it will apply tail on head results

Sed means stream editor it help perform various actions file searching ,insertion and replacing

Sed -n ‘startnumberline,endnumberlinep’ filename-->sed -n ‘5,7p’ employees.csv

After command >filename -->this means inserting data into mentioned file

Head -n 7 employees.csv | tail -n 3 >employee_middle.txt

Means the command output “Head -n 7 employees.csv | tail -n 3” is inserted into file created
employee_middle.txt
More filename-->more employees.csv--> this will show content of file in percentage form like
50% then 75% as page type

Incase u click enter button it will go one record by record

If u enter tab button it will go to next page

Up arrow for seeing previous record

Down arrow for seeing next records

U can use similar command as – less filename-->less employees.csv

To exit from this u need to enter Q in keyboard


Grep – global regular expression pattern

● To search required pattern


grep ‘Hazel’ employees.csv--> it will give output if it finds hazel in file employees.csv

grep -i ‘john’ employees.csv-->i means case insensitive for search purpose

grep -n ‘John’ employees.csv-->grep -n ‘Search’ filename-->n means it will show line number of
record

grep -c ‘John’ employees.csv-->grep -c ‘Search’ filename-->c means count it will show count of
search in whole file

we can add in both command them with -i for case sensitive

grep ‘John’ employees.csv departments.csv--> this will give filename and records details for the
search mentioned
grep -l ‘John’ employees.csv departments.csv-->grep -l ‘Search’ filename1 filename2-->l means
it will show the filename which has the searched string/number/character

Word Count(wc)

wc filename--> this will give no.of_lines no.of_bytes(size of file) count_of_words filename

l-->line numbers , w-->size of file , c-->count of words

SORT-->TO SORT DATA

sort -r employee.txt-->this will sort data in descending order(reverse way)


sort employees.csv --> this will sort data in ascending order by default

sort employees.csv >srteddata.txt --> means it will create a file if not present and if present it will
override the data

sort employees.csv >>srteddata.txt-->means it will create a file if not present and if present It will
append data in the same file

UNIQ-->to find whether file has duplicate data or not only condition is data should ne
sorted for working of uniq

Uniq filename-->uniq emplydata.csv-->This will show unique data of file

Uniq -d filename-->uniq -d emplydata.csv--> This will show duplicate data of the file

Uniq -i filename-->uniq -i emplydata.csv-->this will case in sensitive

Uniq -c filename-->this will count of unique numbers

Uniq -u filename-->this will distinct data of file

Uniq -c employee.csv| grep ‘2’-->this will give which all data having count =2 that duplicate data

Uniq -d filename-->uniq -d employees.csv-->it will duplicates data


gedit filename-->gedit names.txt--> this will create a file and will give text editor interface to
enter the data
uname -a -->will show the whether the operating system used is unix or not

Deleting specific line of file

sed ‘start_line_number,endline_numberd’ filename-->sed ‘1,1d’ employees.csv


tac filename-->tac CustomerDetails.csv--> this will reverse the content order that last line will be
first and vice versa

For removing last lines from files with the help of tac and sed command and d in sed means
delete
Another method of deleting last lines by using variable and “”->double quotes as we are using
variable in command
Command-->Filelist

find /home/nkv/Practice2 -type f | sort > /home/nkv/filelist.txt

Find directory_name will show all directories and files present in that location

-type f will restrict the output only to the files

-type d will restrict the output only to the folders/directories

Sort will sort the output of previous commands -->sort –r will reverse teh order
To get list of folder and subfolders in filelist just replacing –type f to type d

Zipping of file

Zipping can be acheived by gzip or bzip2

Gzip –kv file_name

k--> it will keep the orignal file

v-->verbose data its shows details about the percentage of compression and other details

Gunzip zip_file_name-->this will unzip the file mentioned in zip format

Gunzip –d zip_file_name-->d—decompress

Same commands goes for bzip2 compression method

Stat file_name -->gives the metadata of file


Exiftool file_name -->gives the detail metadata of the files

Df→ gives us the disk space

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy