UNIxnkv
UNIxnkv
UNIxnkv
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
You can mention this in single line itself but the unix will execute them seperately
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
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
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)
/of → this commands makes to search of keyword in the file with highlighted the keyword
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
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 -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
| this means it will apply the after | pipe command before | results
Sed means stream editor it help perform various actions file searching ,insertion and replacing
After command >filename -->this means inserting data into mentioned file
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
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
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)
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 -d filename-->uniq -d emplydata.csv--> This will show duplicate data of the file
Uniq -c employee.csv| grep ‘2’-->this will give which all data having count =2 that duplicate data
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 directory_name will show all directories and files present in that location
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
v-->verbose data its shows details about the percentage of compression and other details
Gunzip –d zip_file_name-->d—decompress