General Flashcards
How would you replace the word linux with linux-KT in a file called samples.txt
sed ‘s/linux/linux-KT’ samples.txt
How to copy a directory and it’s sub directories to a new location?
cp -R /keith /cathy
What is sed use for matching?
Regular expressions
How would you use sed to replace the second occurrence of a word?
sed ‘s/linux/linux-KT/2’ samples.txt
How would you delete the last 3 characters of each line in a file using sed?
sed ‘s/…$//’ samples.txt
How would you string two commands together in sed?
Using the ;
Example:
sed -e ‘s/#.*//;/^$/d’ thegeekstuff.txt
What is sed used for?
Searching and replacing in text files?
How would you search for text in all files in directories and sub directories?
grep -RnisI *
Search for a string inside all files in the current directory
This is how I typically grep. -R recurse into subdirectories, -n show line numbers of matches, -i ignore case, -s suppress “doesn’t exist” and “can’t read” messages, -I ignore binary files (technically, process them as having no matches, important for showing inverted results with -v)
I have grep aliased to “grep –color=auto” as well, but that’s a matter of formatting not function.
Add to favourites | Report as malicious
How to get current directory?
pwd
What is linux cut command used for?
extract portion of text from a file by selecting columns.
What is dd used for in linux?
dd can be used to raw copy a uncounted disk to a file.
What command could I use to get disk io?
Iostat
When swing top on a server with a processor with 4 cores, if the lode average is 4.57, is their processes having to wait ?
Yes
What are the 3 load average times when using top?
Last min
5 min
15 min
In a linux terminal how would you clear the screen?
ctrl-l
How would you search for a package?
apt-cache search
How would you get a lists of all installed packages?
dpkg -l
What syntax would you use to do the following, execute the next command if the current command was successful?
&&
What syntax would you use to have the next command execute if the current command failed to execute?
||
How can you string two or more commands together?
ls ; ls
What command would you use to get PCI info?
lspci -T -V
What command would you use to get a list of hardware info?
lshw
How can you get the nap client to update again a ntp ?service
ntp date -s ntp.ubuntu.com
How would you upgrade a package in linux?
apt-get upgrade
How would you upgrade all software in linux ?
apt-get upgrade
How would you upgrade the linux distribution?
apt-get dist-upgrade
How would you remove a package and it’s config files from linux?
apt-get purge
How would you clean out files from local repositories ?
Clean
What is the location of the cache directories associated with the clean command?
/var/cache/apt/archives/ and /var/cache/apt/archives/partial/
Where is the repo sources for apt-get
/etc/apt/sources.list
How would you do a apt-get install and simulate the operations?
apt-get -s install
With apt-get how would you simulate actions?
Use the -s flag
How to change current user password
passwd
How to shutdown the Linux OS
shutdown now
How to reboot the Linux OX
reboot
How can we create a tar
tar cvzf archive_name dirname/
How can we extract a tar file
tar xvf archive_name.tar
How can we view the continence of a tar
tar tvf archive_name.tar
How can you execute on each file found with the find command?
find -iname “MyCProgram.c” -exec md5sum {} \;
Debug ssh
ssh -v -l jsmith remotehost.example.com
How do you export MYVAR
export MYVAR=xxxxxxxxxx
How do you restart ssh service?
service ssh restart
How do you get the status of a service?
service ssh restart
Check the status of all services?
service –status-all
How can you from command line erase a complete line
ctrl-u
How to delete last word typed in cli?
ctrl-w
How to cancel current operation?
ctrl-c
How to paste previous line?
ctrl-p
If terminal is gone a bit wonky, how would you make it good a gain?
reset
On command line how can you move between args quickly?
ctrl-left ctrl-right
On command line how would you mover the curser to the end of the line quickly?
ctrl-e
On the command line how would you move to the begining of the line quickly?
ctrl-a
From command line how can you search the history for something?
ctrl-r xxxx
On cli how do you delete a line before the curser?
ctrl-w
On cli how to delete line from curser to end of line?
ctrl-k
How can you have command repeated ever 5 sec?
watch -n 5 “tail -n /var/log/sys log”
How can you see the last 30 lines of a file?
tail -n 30
How to show/list all hidden files?
ls -a
How to kill a process bu name?
kill nano
Using scp to to copy a file from local server to remote?
scp @:
scp filename username@host:/path/to/other/destination/directory
With scp to to copy a file from remote to local?
$ scp your_username@remotehost.edu:foobar.txt /some/local/directory
With scp how to copy a directory from local to remote?
$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar
When using the ‘ps aux’ command, what dose the ‘a’ mean?
-a means all process.
When using the ‘ps aux’ command, what dose the ‘u’ mean?
-u select the users that exist in the user list
How would you get a lists of users?
cat /etc/passed
With ps how would you return the command and args used to start the process?
ps aux -o args
How to display a process threads?
ps aux -m
When using ps command how would you get full format info?
-f
What command to use to get the machine hardware clock?
how clock
What command to use to write the linux clock to the hardware clock?
hwclock -w
How to set the hardware date and time manually?
hwclock –set –date “8/11/2013 23:10:45”
How to get a list of kernal modules?
lsmod
How to install a module in kernal?
insmod keith.ko
How to remove module from kernal?
rmmod keith.ko
How to get info about a kernal module?
modinfo /lib/modules/3.5.0-19-generic/kernel/fs/squashfs/squashfs.ko
filename: /lib/modules/3.5.0-19-generic/kernel/fs/squashfs/squashfs.ko
license: GPL
author: Phillip Lougher
description: squashfs 4.0, a compressed read-only filesystem
srcversion: 89B46A0667BD5F2494C4C72
depends:
intree: Y
vermagic: 3.5.0-19-generic SMP mod_unload modversions 686
How to get the first 10 lines of a text file?
head -n 10
How to find files modified in last 5 min?
find / -cmin -5
How to find files modified in last two days?
$ find /target_directory -type f -mtime -2
How to use top to monitor a process by its id?
top -p
Using top how would you monitor all user process?
top -u keith
How to get a list of open files?
ls of
How would you monitor system calls and signals in a program?
sstrace
How to use strace to monitor a existing program?
strace -c
When using strace how can you write to a file?
-o flag
stace -p -o /tmp/dog.txt
How to get a package dependacys?
apt-cache depends ssh
What is apt-get update used for?
Used to re-synchronize the package index files from their sources.
What is apt-get upgrade used for?
Used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list(5).
What is apt-get dist-upgrade used for?
In addition to performing the function of upgrade, this option also intelligently handles changing dependencies with new versions of packages; apt-get has a “smart” conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones, if necessary.
What is the wc command used for
wc - print the number of bytes, words, and lines in files
What is the dig command used for?
To query dns server for info?