About Linux/Linux Commands
The ls command without options or arguments...
...lists the contents of the current directory.
What does the tilde (~) represent in vi?
An unused line
Many Linux systems have a program called bash. What is bash?
Bash (bourne again shell) acts as the shell program.
Deletes from current cursor position to the end of the current line
D
Inserts text at the beginning of the current line
I
How are files in Linux organized?
In a hierarchical directory structure.
What does the pipe command mean?
It can connect two commands together so that the output from one program becomes the input of the next program.
What does the less command do?
It lets you view text files. Ex. less [filename].txt
What does superuser mean?
It means you have the ability to overwrite any file in the system without asking for permission.
find command
It searches for the file name or directory name.
What are meta characters? List important ones.
Metacharacters are characters that have special meaning. For example, * and ? are meta characters. Ex. ls ch*.doc This displays all files, the names of which start with ch and end with doc ? is used to match a single character
Creates new line for text entry above cursor location
O
Deletes the line the cursor is on and replaces it with new text. After new text is entered you are left in insert mode
S
Using grep ...
SYNTAX: grep [options] pattern [files] -----Options Description----- -c : This prints only a count of the lines that match a pattern -h : Display the matched lines, but do not display the filenames. -i : Ignores, case for matching -l : Displays list of a filenames only. -n : Display the matched lines and their line numbers. -v : This prints out all the lines that do not matches the pattern -e exp : Specifies expression with this option. Can use multiple times. -f file : Takes patterns from file, one per line. -E : Treats pattern as an extended regular expression (ERE) -w : Match whole word -o : Print only the matched parts of a matching line, with each such part on a separate output line.
What does it mean if a file begins with a period character ?
The file is a hidden file, and cannot be viewed unless you use the ls -a command
What is a root directory?
The first directory in a system.
mv command
The mv command is used to both move a file to a new directory, and to rename a file. Ex. mv [old directory] [new directory[
What is terminal?
This lets you interact with the shell. Essentially lets you run your code.
Deletes character before cursor location
X
Inserts text after current cursor location
a
List some basic commands when you are viewing a text file. (with less command)
b - scroll back one page space bar - scroll forward one page G - go to the end of the text file 1G - go to the beginning of the text file \[pattern] - searches and highlights the pattern in the text file q - quit h - displays complete list of less commands
command line calculator command?
bc short for basic calculator. Can do basic mathematical calculations. Ex. echo 5+5 | bc This outputs 10 Ex. echo 5^2 | bc This outputs 25
How to display content of a file?
cat command. Ex. cat filename
Removes contents of the line, leaving you in insert mode
cc
cd command & varieties
change directory. cd .. get access to parent directory cd . get access to current working directory cd go back to home directory
How to change permissions of a file?
chmod command. change mode. ***** ??
How to copy a file?
cp command. Ex. cp sourcefile destinationfile
How do you extract sections from a text file?
cut command. This command can be used to cut parts of a line by byte position, character and field. Extract bytes: Ex. cut -b 1-3 filename Ex. cut -b 1,2,3 filename Extract character Ex. cut -c 1-3 filename Ex. cut -c 1,2,3 filename
Changes the word the cursor is on from the cursor to the lowercase w end of the word
cw
Deletes from the current cursor position to the end of the line
d$
Deletes from current cursor position to the beginning of the line
d^
Deletes the line the cursor is on
dd
How do you estimate file space usage?
du command. short for disk usage. The du command can be used to track the files and directories which are consuming excessive amount of space on hard disk drive. du [option][filename] ****???? options:
Deletes from current cursor location to the next word
dw
How to know what data a file has before you view it?
file command. Ex. file [filename] This will tell us if the file is a .txt file, ascii file, etc
How do you globally search for a regular expression?
grep command. Ex. grep [pattern] This searches a file or files for a line that has a certain pattern in the directory that you are Ex. ls -l | grep [pattern] This searches for the pattern in all the listed files Ex. ls -l | grep -v [pattern] This prints all the lines that do not match the pattern Ex. ls -l | grep -n [pattern] This prints all the matches lines and the line number Ex. ls -l | grep -c [pattern] This prints only the count of matching lines Ex. ls -l | grep -i [pattern] This matches either upper or lower case Ex. ls -l | grep -i carol.*aug This tells grep to find lines with carol, followed by a period character, star character, and then aug
Insert text before current cursor location
i
Getting around when editing files (instead of using mouse)
l key - move right h key - move left j key - move down k key - move up
ls -a
list invisible (configured) files
How to find file permissions?
ls -l command. This lists all the files in long format. 1. File permissions (-rw-------) [10] This tells us about the files access permissions. - The first character (starting from the left) tells us about the type of file. A "-" means its a normal file. A "d" means that it is a directory. - The second set of three characters tells us about the read, write, and execution rights of the files owner. - The next three tells us the rights of the file's group, and the last three tells us about the rights given to everyone else. 2. Owner (1 bshotts) The name of the user who owns the file 3. Group (bshotts) The name of the group that has file permissions along with the file's owner 4. Size (576) The size of the file in bytes 5. Modification time Last time file was modified 6. File name
How to rename a file?
mv command. Ex. mv oldfile newfile
Creates new line for text entry below cursor location
o
Puts the copied text after the cursor
p
pwd command
print working directory. When you first login to ta Linux system, the working directory is set to your home directory
Replaces the character under the cursor. vi returns to the command mode after the replacement is entered
r
rmdir command
remove a directory. produces no output if succesful Ex. rmdir [directoryname] Ex. rmdir [directoryname1] [directoryname2]
ls .
represent current directory
ls ..
represent parent directory
How to delete a file?
rm command. Ex. rm filename remove multiple files Ex. rm filename1 filename2
Replaces the current character with the character you type. Afterward, you are left in the insert mode
s
What command can arrange lines of text alphabetically or numerically?
sort command. Ex. sort filename This arranges lines of text alphabetically (by default)
What is an operating system?
the software that supports a computer's basic functions, such as scheduling tasks, executing applications, and controlling peripherals. Ex. Microsoft Windows, mac OS, Linux
How to create a new file?
use vi editor. Ex. vi filename (This either opens up the file in the directory in edit mode, or if that file is non existent, it creates a new file in that directory, and then opens it up)
In Terminal, if you have a $ means you are the ________ otherwise if you have a # it means you are the ________.
user; superuser
How do you open a file only in read mode?
vi -R filename or view filename
How to get word count in a file?
wc command. Ex. wc filename first column - total number of lines in the file second column - total number of words in the file third column - total number of bytes in a file (actual size of the file fourth column - file name can do this to multiple files. Ex. wc filename1 filename2
Deletes character under the cursor location
x
Are file names in linux case sensitive?
yes! Ex. file1 and File1 are two different files
Copies current word from the character the lower w is on cursor is on, until the end of the word
yw
Copies current line
yy
What are the type of operation modes
1. Command mode: can save a file, execute commands, move cursor, find and replace 2. Insert mode: can insert text into a file vi always starts in command mode, in order to get into insert mode you, type i. To come out of insert mode, type esc
Command to quit
:q
Command to quit without saving
:q!
Command to save contents
:w
Command to save contents and quit
:wq
Inserts text at the end of the current line
A
What is interface?
A common boundary were different parts of a system come in contact and interact.
What is a directory?
A directory is a logical grouping of files. Directories are called folders. Directories are useful because they make it easier for a human to relocate files and they allow the repeated use of the same file name in different locations.
What is shell?
A shell is software that a user needs to communicate with the kernel. It takes commands from the keyboard and gives them to the operating system to perform.