Basic unix commands Flashcards
to crack the interviews
create a tar archive file tecmint-14-09-12.tar for a directory /home/tecmint in current working directory
tar -cvf tecmint-14-09-12.tar /home/tecmint
-cvf options specified? no? then rate 2
create a compressed MyImages-14-09-12.tar.gz file for the directory /home/MyImages
tar -cvzf MyImages-14-09-12.tar.gz /home/MyImages
right extension of tar file, no-rate 3
create a Phpfiles-org.tar.bz2 file for a directory /home/php
tar -cvfj Phpfiles-org.tar.bz2 /home/php
options specified? no? then rate 2
right extension of tar file, no-rate 3
untar the file public_html-14-09-12.tar in present working directory
tar -xvf public_html-14-09-12.tar
options specified? no? then rate 2
if said untar instead of tar -x, rate 1
Uncompress tar.gz archive file in different working directory /etc/psswd -the absolute path
tar -xvf public_html-14-09-12.tar.gz -C /etc/psswd
options specified? no? then rate 2
if said untar instead of tar -x, rate 1
right extension of tar file, no-rate 3
Uncompress highly compressed tar.bz2 file
tar -xvf public_html-14-09-12.tar.bz2
options specified? no? then rate 2
if said untar instead of tar -x, rate 1
right extension of tar file, no-rate 3
no j in the options during uncompress-note this
list the content of uploadprogress.tar file.
tar -tvf uploadprogress.tar
options specified? no? then rate 2
list the content of tar.gz file
tar -tvf uploadprogress.tar.gz
options specified? no? then rate 2
right extension of tar file, no-rate 3
list the content of tar.bz2 file
tar -tvf uploadprogress.tar.bz2
options specified? no? then rate 2
right extension of tar file, no-rate 3
extract a single file called cleanfiles.sh from cleanfiles.sh.tar
tar -xvf cleanfiles.sh.tar cleanfiles.sh
command arguments in same order or not? no -rate 3
options specified? no? then rate 2
extract a single file tecmintbackup.xml from tecmintbackup.tar.gz archive file
tar -zxvf tecmintbackup.tar.gz tecmintbackup.xml
command arguments(not options) in same order or not? no -rate 3 options specified? no? then rate 2
extract a single file called index.php from the file Phpfiles-org.tar.bz2
tar -jxvf Phpfiles-org.tar.bz2 index.php
command arguments(not options) in same order or not? no -rate 3
options specified? no? then rate 2
j and respective z options are required here
extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file
tar -jxvf Phpfiles-org.tar.bz2 “file1.xml”,” file2.xml”
tar -zxvf tecmintbackup.tar.gz “file1.xml”,” file2.xml”
tar -xvf cleanfiles.sh.tar “index.php” , “k2.php”
options specified? no? then rate 2 command arguments(not options) in same order or not? no -rate 2
extract a group of all files whose pattern begins with .php from a tar, tar.gz and tar.bz2 archive file
tar -jxvf Phpfiles-org.tar.bz2 –wildcards ‘.php’
tar -zxvf tecmintbackup.tar.gz –wildcards ‘.php’
tar -xvf cleanfiles.sh.tar –wildcards ‘*.php’
options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
add file xyz.txt and directory php to existing tecmint-14-09-12.tar archive file
tar -rvf tecmint-14-09-12.tar xyz.txt
tar -rvf tecmint-14-09-12.tar php
options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
didnt identify which option for append, rate 1
add files or directories to an existing compressed tar.gz and tar.bz2 archive file
tar -rvf tecmint-14-09-12.tar.gz xyz.txt
tar -rvf tecmint-14-09-12.tar.bz2 php
options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
didnt identify which option for append, rate 1
check the size of any tar, tar.gz and tar.bz2 archive file
tar -czvf tecmint-14-09-12.tar.gz xyz.txt | wc -c
tar -cjvf tecmint-14-09-12.tar.bz2 php | wc -c
options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
didnt identify which option for size check , rate 1
see the actual content of that tar file
tar -tvf actualcontent.tar
options specified? no? then rate 2
right extension of tar file, no-rate 3
didn’t understand the question , rate 1
didn’t remember the right option, rate 1
create tar file in Unix with just specified contents
tar -cvf equitytrading.tar equity currency
command arguments(not options) in same order or not? no -rate 2 didn't understand the question , rate 1
view contents of gzip tar file
tar -ztvf trading.tgz
options specified? no? then rate 2
know the size of tar file before creating it
tar -cf - * | wc -c
didn’t understand the question , rate 1
options specified? no? then rate 2
How To Uncompress A Tar.Gz In Another Directory
tar xzf archive.tar.gz -C /destination
didn’t understand the question , rate 1
options specified? no? then rate 2
Using tar -xzvf filename.tar.gz doesn’t extract the file. it is gives this error:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors
If file filename.tar.gz gives this message: POSIX tar archive, the archive is a tar, not a GZip archive.
Unpack a tar without the z, it is for gzipped (compressed), only:
mv filename.tar.gz filename.tar # optional
tar xvf filename.tar
didn’t understand the question , rate 1
options specified? no? then rate 2
don’t remember the solution, rate 3
How to check if a Unix .tar.gz file is a valid file without uncompressing?
What about just getting a listing of the tarball and throw away the output, rather than decompressing the file?
tar -tzf my_tar.tar.gz >/dev/null
This test in no way implies integrity of the data. Because it was designed as a tape archival utility most implementations of tar will allow multiple copies of the same file!
How do I tar a directory of files and folders without including the directory itself?
$ mkdir my_directory $ touch my_directory/file1 $ touch my_directory/file2 $ touch my_directory/.hiddenfile1 $ touch my_directory/.hiddenfile2 $ cd my_directory/ && tar -zcvf ../my_dir.tgz * && cd .. ./ ./file1 ./file2 ./.hiddenfile1 ./.hiddenfile2 $ tar ztf my_dir.tgz ./ ./file1 ./file2 ./.hiddenfile1 ./.hiddenfile2
What is the difference between tar and zip? What are the use cases for each?
tar in itself just bundles files together, while zip applies compression as well.
Usually you use gzip along with tar to compress the resulting tarball, thus achieving similar results as with zip
How can you untar more than one file at a time?
find -iname *.tar -exec tar -xvf {} \
if can’t think of exec or xargs, rate 1
Untar a file in current directory or in a specified directory
tar xvfj file.tar
tar xvfj file.tar -C path of file in directoy
didn’t understand the question , rate 1
options specified? no? then rate 2
don’t remember the solution, rate 3
list only for the mentioned text or image from archived file.
tar tvf file.tar | grep “text to find”
tar tvf file.tar | grep “filename.file extension”
don’t remember the command to use, rate 1
didn’t understand the question , rate 1
–wilcards can’t be used?
views the archived files along with their details like the file name that’s archived in the given tar file
tar tvf file.tar filename
don’t remember the argument to use at the end, rate 1
didn’t understand the question , rate 1
Viewing the Archive file.tar
tar tvf file.tar
don’t remember the argument to use at the end, rate 1
didn’t understand the question , rate 1
Creating an uncompressed archive using tar command
tar cvf archive_name.tar dirname/
don’t remember the options to use , rate 1
didn’t understand the question , rate 1
make a tar file out of two specific files file1, file2 in a specified directory
$ ls abc def $ tar cvf compressed.tar abc def abc def $ ls abc compressed.tar def
if dont know that passing specified filenames is an option to tar only them, rate 1
Listing an uncompressed archive using tar command
tar tvf archive_name.tar
didn’t understand the question , rate 1
don’t know listing imples option t, rate 1
Listing a compressed archive using tar command
tar tvfz archive_name.tar.gz
tar tvfj archive_name.tar.bz2
didn’t understand the question , rate 1
don’t know listing imples option t, rate 1
don’t know what compressed archive imples option t, rate 1
You cannot add file or directory to a compressed archive. If you try to do so, you will get “tar: Cannot update compressed archives” error
do u know this very well?
estimates the tar file size ( in KB ) before you create the tar file
tar -cf - /directory/to/archive/ | wc -c
Find all the files whose name is tecmint.txt in a current working directory
find -name techmint.txt /path/to/current/working/dir
shouldn’t be your answer
The right answer is
find . -name techmint.txt
-name option if not specified, rate 1 if doesnt strike that . = current working dir, rate 1 command arguments(not options) in same order or not? no -rate 2
Find all the files under /home directory with name tecmint.txt
find /home -name techmint.txt
if not specified the full file name with extensions, rate 3
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.
find /home -iname techmint.txt
if not specified the full file name with extensions, rate 3
if not specified the i letter before name , rate 1
Find all directories whose name is Tecmint in / directory.
find / -name Techmint
The question implies that techmint is the name for multiple directories, if dont understand this -rate 2
if any quotations are added, rate 4 coz its plain-no quotations
Find all php files whose name is tecmint.php in a current working directory
find . -type f -name techmint.php
if missed the type -f option-it could bring in directories with such name too(possible)- rate 2
If don’t watch out that the question only asked for files and not the directories- rate 1
Find all php files in a directory
find /path/to/dir -type f -name “*.php”
If don’t understand that its a wildcard or regex -rate 2
if don’t put it in “”, rate 2
if don’t put along with the -name option, rate 1
Find all the files whose permissions are 777
find . -type f -perm 0777 -print
if don’t know that / means check all dirs in current dir, rate 1
if are specific that you want to print to std out like screen, rate 5
Find all the files without permission 777
find . -type f ! -perm 0777 -print
if don’t know that ! means a negation before an option, rate 1
Find all the SGID bit files whose permissions set to 644
find . -type f -perm 2644
if the first bit is set to 2 , sgid bit is set-dont know this rate 1
Find all the Sticky Bit set files whose permission are 551
find . -type f -perm 1551
if the first bit is set to 1 , sticky bit is set-dont know this rate 1
Find all SUID set files
find . -type f -perm /u=s
if don’t remember that -perm option is used, rate 1
if don’t remember the argument to -perm userid set bit which is /u=s(set suid), rate 1
Find all SGID set files.
find . -type f -perm /g=s
if don’t remember that -perm option is used, rate 1
if don’t remember the argument to -perm userid set bit which is /g=s(set sgid), rate 1
Find all Read Only files
find . -perm /u=r
if don’t remember that -perm option is used, rate 1
if don’t remember the argument to -perm userid set bit which is /u(user)=r(read), rate 1
Find all Executable files
find . -perm /u=x
if don’t remember that -perm option is used, rate 1
if don’t remember the argument to -perm userid set bit which is /a(any user or all )=x(execute), rate 1,
use /u(user)=x rate 3
Find all 777 permission files and set permissions to 644
find . -perm 0777 -exec chmod 0644 {} /;
If don’t remember that -perm option is used, rate 1
if don’t remember that -exec option is used, rate 1
if don’t remember that {} ‘; syntax is at the end of -exec option, rate 1
If don’t remember that -chmod option is used to set permissions, rate 1
Find all 777 permission directories and set permissions to 755
find . -type d-perm 0777 -exec chmod 0644 {} /;
if don’t note that the permissions are to be set for directories, rate 1
If don’t remember that -chmod option is used to set permissions, rate 1
If don’t remember that -perm option is used, rate 1
if don’t remember that -exec option is used, rate 1
if don’t remember that {} ‘; syntax is at the end of -exec option, rate 1
find a single file called tecmint.txt and remove it
find . -name techmint.txt -exec rm -rf {} /;
If don’t remember that -rm option for deleting or removing, rate 1
If don’t remember that -perm option is used, rate 1
if don’t remember that -exec option is used, rate 1
if don’t remember that {} ‘; syntax is at the end of -exec option, rate 1
find and remove multiple files such as .mp3
find . -name “*.txt” -exec rm-rf {} /;
if don’t remember multiple files with a pattern has to be in “ “, rate 1
find all empty files under certain path
find . -type f -empty
if don’t remember , -empty is an option , rate 1
find all empty directories under certain path
find . -type d -empty
if don’t remember , -empty is an option , rate 1
if don’t notice the question is on directories , and use -type d , rate 1
To find all hidden files
find . -type f -name “ .*”
if don’t remember that . is the pattern of the hidden file start-rate 1
find all or single file called tecmint.txt under / root directory of owner root
find / -type f -user root -name techmint,txt
if don’t remember that the option is -user ,rate 1
if the options are in wrong order, rate 3
if dont rememeber / corresponds to root dir, rate 1
find all files that belongs to user Tecmint under /home directory
find /home -user Techmint -type f
if added any extra options like -name , rate 1
if the options are in wrong order, rate 3
find all files that belongs to group Developer under /home directory
find /home -group developer -type f
If don’t remember that the option is -group ,rate 1
if added any extra options like -name , rate 1
if the options are in wrong order, rate 3
find all .txt files of user Tecmint under /home directory
find /home -type f -iname “*.txt” -user Techmint
if don’t remember that the option is -user ,rate 1
if the options are in wrong order, rate 3
if dont rememeber / corresponds to root dir, rate 1
find all the files which are modified 50 days back
find . -type f -mtime 50
if don’t remember that the option is -mtime ,rate 1
if have any + or - sign , rate 3,since asked just precise 50 days
find all the files which are accessed 50 days back
find . -type f -atime 50
if don’t remember that the option is -atime ,rate 1
if have any + or - sign , rate 3 ,since asked just precise 50 days
nd all the files which are modified more than 50 days back and less than 100 days
find . -type f -mtime +50 -mtime -100
If don’t remember that the option is -mtime ,rate 1
If don’t remember that the option is -mtime should be used two times to specify range ,rate 1
f don’t remember that the option is -mtime arguments have +, - signs ,rate 1
find all the files which are changed in last 1 hour
find . -type f -cmin 60
if confused with cmin and mmin, rate 3
if don’t remember the cmin option, rate 1
if don’t remember the arguments are in minutes count, rate 1
find all the files which are modified in last 1 hour
find . -type f -mmin 60
if confused with cmin and mmin, rate 3
if don’t remember the cmin option, rate 1
if don’t remember the arguments are in minutes count, rate 1
find all the files which are accessed in last 1 hour
find . -type f -amin 60
if confused with cmin and mmin, rate 3
if don’t remember the cmin option, rate 1
if don’t remember the arguments are in minutes count, rate 1
find all 50MB files
find / -type f -size 50M
if don’t remember the -size option, rate 1
if don’t remember the option’s argument needs to specify the unit of size, rate 1
find all the files which are greater than 50MB and less than 100MB
find / -type f -size +50M -size +100M
If don’t remember that the option is -size ,rate 1
If don’t remember that the option is -size should be used two times to specify range ,rate 1
f don’t remember that the option is -size arguments have +, - signs ,rate 1
if don’t remember the option’s argument needs to specify the unit of size, rate 1
find all 100MB files and delete them using one single command
find / -type f -size 100M -exec rm -rf {} /;
if don’t remember the -size and -exec for deleting -rm, rate 1
Find all .mp3 files with more than 10MB and delete them using one single command
find / -type f -name “*.mp3” -size +10M -exec rm -rf {} /;
Symbol 1 f 2 d 3 b 4 c 5 p 6 l 7 s
Type Regular file Directory file Block file Character file Pipe file Symbolic link file Socket file.
Search for all the files whose StickyBit is set
find / -perm /o=t
if dont know o means others and t is for sticky, rate 1
Search for all the files whose owener permissions is read only
find / -perm /u=r
if don’t know u means owner and r is for read pnly , rate 1
Search for all the files which have user, group and others with executable permissions
find / -perm /a=x
if don’t know a means owner, user and all others and x is for execution , rate 1
want to get all the files which are created later this file creation newer.txt .
find / -newer newertxt
need to know that -newer is an option, rate 1 if no
Search for files whose size is more than 10bytes
find / -type -f -size +10c
if don’t now that c is used for bytes notation of size in units, rate 1
Search for files which are exactly 10kb in /opt folder
find /opt -type -f -size 10k
if don’t now that k is used for kilo bytes notation of size in units, rate 1
find all the empty files in my system
find /opt -type -f -size 0k
if don’t now that k is used for kilo bytes notation of size in units for empty files too , rate 1
Search for files which are more than 1GB size in /usr folde
find /opt -type -f -size +1G
if don’t now that G is used for giga bytes notation of size in units, rate 1
Find all the files with SGID for the group sales and with size exactly 100MB with file name as pass.txt under /opt.
find /opt -size 100M -group sales -perm g+s -name pass.txt
Find all the files which are more than 100MB and less than 1GB in size.
find / -size +100M -size -1G
if don’t know to put appropriate units near the -size’s argument, rate 2
: find a file with passwd.txt in /var folder and long list this file for checking file properties
find /var -iname passwd.txt -exec ls -l {} ;
if dont remeber long listing option is for ls , rate 1
Find all the files with name test.txt in /mnt and change the ownership of the files from Surendra to Narendra
find /mnt -type f -name test.txt -user Surendra -exec chown Narendra {} \;
if don’t remember that exec needs to be used, rate 1
if don’t remember that chown needs to used with exec to do modifications on the found files, rate 2
if added extra options with chown, rate 3
finding a file with inode number
find /mnt -type f -inode 23
if don’t remember the inode number , then rate 2
Find all the files with name test.sh in /abc folder and then grep if for word is there in that file or not
find /abc -type f -name test.sh -exec grep “for” {} \;
Find all the files with name xyz.txt owned by Surendra in /var/ftp/pub and change the permissions to 775 to them.
find /var/ftp/pub -type f -name xyz.txt -user Surendra -exec chmod 775 { } \;
make sure you have included all the filter options, rate 4 if missed
Find all the files with name temp.txt in /xyz folder and backup then compress them to send it for saving
find /xyz -type f -name temp.txt -exec tar -cvfz backup.tar.gz {} /;
any small obvious mistake , rate 1
Find files with name abc.txt in /home directory and take backup of each file before modifying it
find /xyz -type f -name temp.txt -exec cp {} {}.bkf /;
If doesn’t strike to use cp command, rate 1
if don’t remember that cp follows w=by the current path of the file represented by {} in -exec command , rate 1
If don’t remember the cp syntax, rate 1
Find all the files with executable permissions and display their checksum value
find /con -type f -perm /a=x -exec -md5sum {} \;
if don’‘t remember that md5sum is the command for the checksum, rate 1
Find all the files with name abc.txt and owner as surendra then move them to /opt folder
find /com -type f -name abc.txt -user surendra -exec mv {] /opt/ \;
If doesn’t strike to use mv command, rate 1
if don’t remember that mv follows by {}. rate 1
the current path of the file represented by {} in -exec command , rate 1
If don’t remember the mv syntax, rate 1
Find files with abc.txt name in /opt directory change the owner permissions from Surendra to Narendra and change the permissions to 775
find /com -type f -name abc.txt -user surendra -exec chown Narendra \; -exec chmod 775 \;
If you don’t remember that We can use this multiple -exec option more than two times, rate 2
Find abc.txt file in /opt and /var folder at a time
find /opt /var -name abc.txt
If you don’t remember that two locations can be specified side by side, rate 2
Search multiple locations but not in particular location. Find abc.txt file in /opt and /var folder at a time, Search in entire system expect /proc folder
find /opt /var -path /proc -prune -name abc.txt
if don’t remember this - The -path variable to define the path of a location. And -prune combined with -path will say not to descend in to the mention path /proc- rate 1
search for abc.txt and hash.c file at a time
find /opt /var -name abc.txt -o -name hash.c
if don’t know that the -o should be followed by the specific previous option , rate 3
if don’t know h=that -o option should be used to find for something together, rate 1
find two directories say opt and var how can i find them
find . -type d -name opt -o -type d-name var
if don’t understand the question, rate 1
if doesn’t strike that its type d option, rate 1
Finding files only in the current directory not searching on subdirectories
find . -maxdepth 1 -type f -newer first_file
if don’t remember the maxdepth option, rate 1
find all of the symbolic links in your home directory, and print the files your symbolic links points to
find . -type l -print0 | xargs -o ls -ld | awk ‘{print $10}’
10th field has the actual link pointing, remember if forgot, rate 3
if forgot about the awk syntax, rate 2
if forgot about symbolic links , rate 1
always use find -print0 along with xargs -0 if you see slightest possibilities of file names containing space in UNIX or Linux
know this or not
/bin for what
executable files
/ for what
root dir
/etc
config files
/tmp for
only temporary files, they clear during boot time
/opt for
installing software not bundled with os
/var for
log files created by programs and applications
/cdrom for
mount point for files on cdrom
/media for
mount point for cdrom and dvd
/srv for
web files, ftp server files /srv/ftp
/opt/avg/bin
executable files
/etc/opt/myapp
configuration files
/var/opt/myapp
log files
long listing of files and dir
ls -l
long listing of hidden files
ls -la
listing of only files not directories
ls -F
@ link
/ dir
* binary executables
how to execute a binary execuatable file
./binaryfilename
listing of files with time
ls -t
listing of files recursively
ls -R
listing of directories only
ls -d
ls -R alternative is
tree
listing of files in revers order, can this command be confused with anything elsr
ls -r
yes with ls -R which is a recursive listing not reverse listing
directory structure
tree -d
tree - c to colorize output
listing with colorized output
ls –color
edit a file using editor
vi filename
modes of vi
3
command, insert, line
get into vi command mode by
ESC key
get into vi insert mode by
i - to insert right at after the cursor
in vi insert mode, to append right after cursor is
A
in vi insert mode, to append at the beginning of the line is
a
in vi insert mode, to insert at the beginning of the line is
I
what are the navigation commands in command mode
h left j down k up l right
how to get into line mode in vi
type : followed by the command
to save writes in line mode
:w
to force save writes in line mode
:w!
to quit in line mode
:q
to force quit in line mode
:q!
to save writes and force quit, its alternative also in line mode
:wq! :x
navigating through lines in line mode, to position cursor at line n
:n
navigating through lines in line mode, to position cursor at the line end
:$
navigating through lines in line mode, to turn on line numbers
:set nu
navigating through lines in line mode, to turn off line numbers
:set nonu
navigating the command mode, to delete a character
x
navigating the command mode, to delete a word
dw
navigating the command mode, to delete a line
dd
navigating the command mode, to delete from current position
D
navigating the command mode, to change current character
r
navigating the command mode, to change current word
cw
navigating the command mode, to change current line
cc
navigating the command mode, to change from current position
C
navigating the command mode, to change case of a charecter
~
copy a word in command mode vi
yy
in command mode vi , copy 3 words
y3w; y
in command mode vi, paste the copied or deleted word
p
in command mode vi, undo
u
in command mode vi, redo
Cntrl+ R
to search in vi, line mode- forward searching
/pattern ( n for next, N for previous match)
to search in vi, line mode- backward searching
? n for next, N for previous match
Display current running processes
ps
Display current running processes not owned and running as you
ps -e
Display the full format of the process
ps -f
Display process running on root
ps -u root
Display process details of process 123
ps -p 123
Display process tree
ps -e –forest
pstree
Interactive process view
top
What are environment variables for
they specify storage location and has a name and a value, they affect the way programs behave
the command to know all the environment variables
printenv
List few names of environment variables
TZ,HOME,PATH
another way than printenv to print the contents of environment variables are
echo $ENVIRONMENT VARIABLE NAME($HOME)
Create an environment variable name VAR with a value -value
export VAR=’value’
Update an environment variable EDITOR to vi
and TZ environemnt variable to ‘US/Pacific’
export EDITOR=”vi”
export TZ=”US/Pacific”
Remove environment variable TZ to revert it’s value to default
unset TZ
Does an unset and export command persist changes between logins?
No,
How to persist changes in environment variables between logins
vi .bash_profile
insert mode, go to the end export TZ="US?Pacific" \:wq! exit login to shell printenv TZ or echo $TZ
what is the pager utility to print output upto the screen fit
pipe the output to less command
How to tell if a particular program or an application is using a particular environment variables
man commandname will display the man pages with a section on environment variables
command for background process
&
what to do to kill a foreground process like:
sleep 300
Cntrl + C
what to do to suspend a foreground process like:
sleep 300
Cntrl + Z
How to foreground a background process
fg %jobid ;fg %3
How to background a running foreground process
bg %jobid; bg (will background the latest process evoked)
How to kill a job
kill %jobid; kill %3 kill pid; kill 103458 kill -TERM pid; kill -TERM 123 kill 15 123 kill -9 123 (9 kill signal)
what is kill’s kill signal
9
what is kill’s termination signal
15
what is signal 15’s in kill, it’s also used interchangebaly
-TERM
command to list all the jobs
jobs
command to list job details of a job with id 1
jobs %1
command to list the current job(recent /latest job id)
job %+
command to list the previous job id
job %-
what in unix helps to do time based job scheduling
cron services
Tell more about cron services
cron job starts when the system boots,
it performs routine maintenance
and it automates a process
syntax of thecrontab command
min hr dom month dow /path/to/the/executable/file min(0-59) hr(0-23) (dom= day of the month) (1-31) (dow=day of the week)(0-6)
schedule a cron job located at /opt/sales/bin/weekly-report every monday at 7 pm
min hr dom month dow
0 19 * * 1 /opt/sales/bin/weekly-report
perform a half hourly check
0,30 * * * * /opt/sales/bin/weekly-report */2 * * * * /opt/sales/bin/weekly-report
perform a check every first 5 min of the hr
0-5 * * * * /opt/sales/bin/weekly-report
Perform a cron job annually
0 0 1 1 * /opt/sales/bin/weekly-report
Perform a cron job weekly
0 0 * * 0 path/to/the/executable/file
Perform a cron job monthly
0 0 1 * * path/to/the/executable/file
Perform a cron job daily
0 0 * * * path/to/the/executable/file
Perform a cron job hourly
0 * * * * path/to/the/executable/file
What command manipulates cron jobs
chrontab command
command to install a cron job from file
crontab file
command to list cron jobs
crontab -l
command to edit cron job files
crontab -e (should open ur favrt editor: set an environment variable)
command to remove all your cron jobs
crontab -r
how to create a cron job
1) open a vi editor with the file name => vi my-cron
2) in insert mode type 07 **1 /opt/sales/bin/weekly-report
3) :wq!
4) install the file with crontab command => crontab my-cron
5) echo $ EDITOR
6) export EDITOR =vi
7) crontab -e to do any edits
command as a way to start a session as another user is
su
how to start a session as root user
su with no arguments
execute a command by starting a session as a root user
su -C command; su -C ls -l
command to know the what is the current user in our session
whoami
how to stay with the same environment while switched as a user
su oracle ( with out - before the user name )
how to change to the user’s environment while switched as a user
su - oracle (with the - and space followed by a username)
command to switch user to obtain privileges and security of super user
sudo
Does sudo prompts for a password?
yes
list of available commands as superuser switching
sudo -l
to execute a command as privileged user sqoop
sudo -u sqoop command
to execute a command as privileged user sqoop and also switch to the users environment
sudo su - sqoop command
command to start a shell as root
sudo -s
command to start a shell as sqoop
sudo -u sqoop -s
command to modify sudo configurations
sudo visudo
command to copy files from one local machine to linux server
scp source destination
scp z.txt linuxserver(hostname):~ (~ shortcu for hoe dir)
command to copy files from one local machine to linux server interactively
sftp linuxserver
pwd
ls
lpwd # local path to directory
lls # local list files
put z.txt
ls
rm z.txt
quit
Transfer this z.txt file as different user: adminuser
scp z.txt adminuser@linuxserver:/home/adminstration
or
sftp adminuser@linuxserver
pwd
ls
lpwd # local path to directory
lls # local list files
put z.txt
ls
rm z.txt
quit
command to find difference between contents of file 1 AND file 2
diff file1 file2
explain the output of diff file1 file2 command : 3c3
file1lineno change - c file2lineno
if the difference between two files is addition of txt at the 8th line then o.p of diff file1 file2 would be
4a4
if the difference between two files is addition of txt at the 8th line then o.p of diff file1 file2 would be 4a4, Now to see what line was added and the diff the command woud be
sdiff file1 file2
or vimdiff file1 file2 (to view ffiles in two diffent windows)
symbol for differing lines
> lines exist only in 2nd file
< lines exist only in 1rst file
To quit seeig both the file windows using vimdiff command then
:qa!
To quit seeing both the file windows using vimdiff command then
:q
Command to remove file
rm file
command to reove directory
rm -r -dir
command to copy a lift of files to /home
cp file1 file2 /home
command to copy files into a dir that doesnot exist
cp -r file /newdir
command to move or rename files
mv source destin
command to sort file based on the field no
sort -k 10 # 10 is field no