Learning Unix Flashcards
how to check hostname?
hostname
How to check your current location
pwd
How to check system date and time
date
how to check system date/ Current date
date +%D
How to check system time
date +%T
How to check only hour
date +%H
How to check with Hour with min
date +%H:%M
How to check file and directory/ Folder we have in present location
ls
How to display the detail explanation about files and folder
ls -ltr
How to know the file size in kb/mb
ls -lh
How to clear the terminal
clear
How to create any folder
mkdir folder_name/directory
how to enter new folder
cd folder_name
how to create file
touch file_name
So that means you can actually add any file you’d like
How to open any file name
cat file_name
view file_name
less file_name ( Shift+g is to go last line of the terminal ….. press p to read the first line
How to edit any existing file
vi file_name
How to remove/delete any file
rm file_name
how to delete folder/directory
rmdir folder_name OR rm -rf folder_name
How to change/rename existing file_name
mv old_file_name new_file_name
How to move one file from one location to another
mv file_name path(where we want to move that file)
How to copy any file
cp file_name new_file_name
how to display first four lines
head -4 file_name
how to display last four lines
tail -4 file_name
How to read or display top 5 lines from any file
head -5 file_name
How to read display or display bottom/last 10 lines from any file
tail -10 file_name
How to sort the content from a file
sort file_name
How to sort the content and then put the sort content into the new file
sort file_name > new_file_name
How to reverse sort the content
sort -r file_name
How to display a unique content/record from a file
sort file_name | uniq
If a file has 16 lines how to split this file in 3 different file ?
split -1 4 file_name
How to search a word and to display any word from a file
grep “word” file_name
How to search multiple word from a file
egrep “first_word”|second_word” file_name
How to create 10 files by using range of pattern
touch {1..10}
How to count number of lines in any file
wc -1 file_name
How to count word in any file
wc -w file_name
How to count total character in any file
wc -c file_name
d——->
r——–>
w——–>
x———>
This is basically understanding what each letter stands for and what it
-> directory
-> read
-> write
-> execute
- ?
What are these used for ?
- that means to take permission
+ is used to give permission
When it’s time to read, write, or execute what are the numbers you would use to command in UNIX ?
And what number would you use when it’s time to use all permission( read, write, execute) ?
r —->4
w —–> 2
e —–> 1
(r,w,e) —-> 7
When dealing with rwx, what are the first three reasons why we use them ?
- rwx = user/developer/creator
- rwx = group member
- rwx = for client and other team member
What unix command is used to give or take permission to any file/directory( folder)
chmod
We want to give read, write, and execute permission to developer and no other permission to client or team member ?
chmod +700 file_name
The reason why its “700” is because there is NO permission to client thats why we added 0 . We gave permission once that was the issue
Give read permission to developer and read,write, permission to team member and read permission to other team (a.sh)
chmod +464 file_name
Take execute permission to group member and other client
chmod -011 file_name
Take read and write permission to developer and execute permission to group member and other clients
chmod -611 file_name
Write a unix command to give read and write permission to user, read and execute permission to team member and read permission to other team member/client
chmod +654 file_name
What are variables in unix ?
A variable is a character string to which we assign a value
How to create a script and how to run it ?
!/bin/bash and # First line of script
echo "My name is parth"
the echo is how you would right the script
Write a script where I need to take 2 variables name = Parth and age = 33 and print below string
“ My name is Parth Shorey and my age is 33”
!/bin/bash
name = ‘ Parth Shorey’
age = 33
echo “My name is Parth shorey and my age is 33”
What are the three commands to run scripts ?
- ./ script_name
- bash script_name
- path/ script_name