LPIC-1 C3 Commands
.tar cvf archivname.tar /home/myname/mydirectory/*
# Create a tar archive of all files in a particular directory; c = create; v = verbose... filename details; f = name of archive being created... must be last
pr -d -l 10 filename
-d adds a space in between lines; -l sets the max nbr of lines to print per screen
cat -n /etc/passwd
-n prints to the screen with number lines
Normal mode
Also known as command mode; Default mode accessed by pressing Esc key while in insert mode
sort /etc/passwd
Arrange lines in alpha order
nice -10 apt-get install apache2
Assign value 10; Equivalent to run when resource demand is low
nice --10 apt-get install apache2
Assigns a negative nice value; Places a priority on running the process and using resources
nice
Assigns linux resources based on assigned value between 19 and -20; 19 = nice; -20 = nasty
grep non regex characters
Backslash \ Caret ^ Dollar sign $ Dot . Pipe symbol | Question mark ? Asterisk * Plus sign + Parentheses () Square brackets [] Curly braces {}
What type operations are used within vi command line mode?
Basic file management
fg [job_spec]
Bring job [job_spec]to the foreground from background; Continue a stopped job by running it in the foreground
How would grep interpret metacharacters as literal characters?
By placing string inside quotations; precede metacharacter with a backslash \
renice -10 -p 3745
Change nice value of process 3745 to 10
metacharacter
Characters that have a special meaning; example: ^, $, *
:q command line operation
Close vi without saving the current file
paste
Command to merge contents of multiple files
Unexpand
Convert (every # of specified) spaces to tabs
cat /etc/passwd | tr "a-z" "A-Z"
Convert all lowercase to uppercase
unexpand -t 3 filename
Convert every tab to 3 spaces
expand -t 10 filename
Convert tabs to 10 char (spaces) apart
expand
Convert tabs to spaces
dd if=/dev/sdb1 of=/media/usb/partitionbackup
Copy a partition called sdb1 to usb partition called partitionbackup
cp
Copy command
cp myfile /home/myname/Desktop/
Copy file myfile to Desktop directory
scp filename [email protected]:/home/myname/ && rm filename
Copy filename to a remote system; Delete the original only if the copy was successful
sudo find ./ -maxdepth 4 -name "*.txt" | cpio -o > /home/ubuntu/archivename.cpio # created similar to previous tar, but with cpio
Create archive with cpio; Find at root level, 4 levels down, files .txt extension; Pipe thru xargs which allows command execution on streaming data; Create a new .cpio archive
sudo mkdir /etc/newdir
Create with root access privileges
sudo mkdir -p /etc/path/to/mydirectory/
Creates a nested hierarchy of directories
mkdir
Creates a new directory
mkdir newdir
Creates a new directory named "newdir' in current dir
touch
Creates a new, empty file and updates access time metadata
echo $USER
Display current account name populated with USER variable
echo $PWD
Display current working directory
wc
Display document statistics... word and byte counts
top
Display information about running processes and who's running them
env
Display list of current variables... not local or functions
wc /etc/passwd
Display total number of lines, words and bytes in specified file
kill -l
Displays all signals available and their value
file
Displays file details
history
Displays the content of .bash_history file
history | grep .bash_history
Example... This would display the occurrence of ".bash_history" within the .bash_history file.
How would you create a local variable "myvariable"?
Example... myvariable=hello
xargs
Extended arguments... can build and execute command lines from standard input
egrep
Extended grep; Has a larger list of characters it reads as metacharacters
.bash_history file
File where command history is saved
fmt -t filename
Indent all but the first line of a paragraph
screen
Lets you multiplex terminal windows; Allows running mor than one process from a single terminal; May have to install (sudo apt-get install screen)
jobs
List all processes running in the background of current shell
ls -l | tee list.txt
List contents of current directory with details; tee command (as in T splitter) pipes output to multiple targets... including list.txt and stdout
ls
List files and directories
ls -lh
List files and file attributes; Human readable
ls -a
Lists all files including hidden ones... those identified with a "." in front of their name
pgrep
Look up signal process based on name
join
Merge two files with overlapping columns; ex: join column1 column2
mv myfile /home/myaccount/Desktop/
Move file myfile to new location and keep same file name
mv
Move files... the original file is deleted
vi modes of operation
Normal (command); Insert; Command line
When are variables available, when created in Bash session?
Only in current Bash session
uniq -u text.txt
Only print lines that are not repeated
uniq
Only prints lines unique to the file... file needed to be sorted for this to work
tail
Output the last part of a file (10 lines)
join column1 column2 > newfilename
Output to new file
:w! command line operation
Overwrite the existing file
ls | cpio -0 > myarchivename.cpio
Pipe output from list directory command to create archive
ls | cpio -0 | gzip > myarchivename.cpio.gz
Pipe output from list directory command to create archive; Add compression with gzip
How do you access Command mode within vi while in insert mode?
Press Esc key
paste -s column1 column2
Print files sequentially
sort -n /etc/passwd
Print lines in numeric order
sort -r /etc/passwd
Print lines in reverse alpha order
cat -n /etc/passwd | sort -nr
Print lines in reverse numeric order
tail -f /var/log/syslog 1> log-data.txt
Print new entries to syslog file and pipe the standard output to a file
head -10 filename
Print only first 10 lines of a file
uniq text.txt
Print only the first time a repeated line appears
tail -n 3 /etc/passwd
Print only the last 3 lines of the passwd file
od
Print text file in octal format; ex: od filename
The head and tail commands, allow you to view the first few or last few lines of a file (____ lines by default).
Prints only a specified number of lines from front or back end of a file
:q! command line operation
Quit without saving changes
cut -d: -f1 /etc/passwd
Reads the passwd file; Sets a delimeter as a colon (-d:) so when a colon appears in the text, cut will then start a new text field; Print only the first field of every line (-f1)
sort
Rearrange how lines are displayed
sudo cp -r /home/myname/mydirectory/ /usr/share/place/
Recursive argument (-r) copies everytthing in and beneath "/mydirectory/" to /usr/share/place
tar cvf newarchive.tar /dev/sdb1 2> error.txt
Redirect error text output to file error.txt; Create archive; Verbose... list files processed; Filename of archive you're creating
regex
Regular expression; A sequence of characters understood to be either metacharacter (special meaning) or regular character with literal meaning
rm -r *
Removal acts on all the files in a directory
rm
Remove files and directories; ex... rm myfile
rm -r newplace
Removes the directory and its files
mv myfile newname
Results in file myfile being renamed to file newname
apropos
Returns the names of all man files that seem relevant to search string used with the command; Example... apropos zip would return names of relevant files
:w command line operation
Save the current file to disk... will prompt for filename
ls | grep "(this"
Search for file names that include the string "(this"
ls | grep \(this
Search for file names that include the string "(this"
scp
Secure remote file copy;
killall <processname>
Sends kill signal to all processes for identified process name
free
Show how much RAM is being used
free -h
Show megabyte and gigabyte info
Common kill signal values
Signal 1 = sighup... parent shell is closing ("signal hang up"); Signal 2 = sigint... interrupt, which is same as Ctrl-c; Signal 9 = sigkill... shutdown; Signal 15 = sigterm... terminate signal
fmt
Simple text formatter which formats how text is printed to the screen
cut -d:
Specifies that a colon (:) will be a field delimeter
bg [job]
Specify job you want to run in the background
split -2 filename
Splits file into multiple files of two lines each... named xaa, xab, xac, ...
stderr
Standard error defined by 2
stdin
Standard input defined by 0
stdout
Standard output defined by 1
fmt -w 60 filename
Start a new line after 60 characters
kill <pid>
Stops process ID listed with the command
cat filename 2> errors.txt
Stream contents of filename and pipe stderr output to a file; If no error, output file will be empty
sed
Stream editor command for filtering and editing text
cat text.txt | sed s/hello/"goodbye"/g
Substitution is done globally for all occurrences of the specified word
cat text.txt | sed s/hello/"goodbye"/
Takes input from a stream via cat and substitutes a specified word for the first occurrence; Replaces "hello" with "goodbye"
.tar
Tape archive
.less
Text reader program used to view files instead of opening them
tr
Transform text
fgrep (grep -F)
Treats all characters as literal; Works quickly
How do you access vi insert mode while in normal mode?
Type i followed by Enter key
How do you access vi command line mode?
Typing a colon ":" and pressing Enter key
Breakdown the following command: sudo find . -maxdepth 4 -name "*.txt" | xargs tar cvf textarch.tar # use tar on data streams
Use find at root level; Down 4 levels; For files with names that include .txt extension; Pipe thru xargs which allows command execution on streaming data; Create a new archive textarch.tar
.bz2
bzip2 uses what extension
split
command to divide a single file into mult files of specified length
dd
convert and copy a file
cpio
copy files to and from archives
unset
deletes variables
uname -a
display Linux kernel and installation information
How would you display the content of locally created variable "myvariable"
echo $myvariable
How would you make a local variable available for new shell sessions?
export command; Example... export myvariable
Alternate way to write egrep command
grep -E
.gzip
gzip and gunxip uses what extension
ls -s
lists files and subdir in long form
e
r
renice -10 -u tony
renice applied to processes associated with user tony
renice -10 -g audio
renice applied to processes owned by a particular group... "audio" in this example
ps
report a snapshot of the current processes; Displays all processes used by current shell
sudo cp myfile /home/anothername/Desktop/
root access needed to copy to a location outside your acct
cut -d
specifies a character to be used as a field delimiter; The default is a tab
Three streams open for linux commands
stdin stdout stderr
rm -ri newplace
the i makes the process interactive and will prompt you, to confirm this is what you want to do
q
w
pr
Formats text files for printing
:e! command line operation
Walk back changes since last write
x; ex. tar xzvf archivename.tar.gz
What parameter is used to decompress and extract files from a .tar tape archive?
add z... ex tar cvfz arvchivename.tar ...
What parameter would add compression to tape archive
Rm file?
Will delete any file that contains the word file and any additional characters
rm file?
Will delete files that contain the word file and any single additional character
paste column1 column2
Without arguments, prints files side by side
:exit command line operation
Write the current file and exit vi editor
:wq command line operation
Write the current file, then exit; Same as :exit
.xz
Xz uses what extension