Podcast
Questions and Answers
When using the man
command, which section number would you typically consult to find information about functions available within program libraries?
When using the man
command, which section number would you typically consult to find information about functions available within program libraries?
- 1
- 4
- 2
- 3 (correct)
You are currently in the /home/user/documents
directory. Which command would you use to navigate directly to your home directory?
You are currently in the /home/user/documents
directory. Which command would you use to navigate directly to your home directory?
- $ cd /
- $ cd .
- $ cd ..
- $ cd ~ (correct)
What is the primary function of the help
command in a Linux shell environment?
What is the primary function of the help
command in a Linux shell environment?
- To provide a list of available external commands and their usage.
- To access and display user manuals for all installed software packages.
- To display detailed information about system calls and kernel functions.
- To offer information and usage examples for shell built-in commands. (correct)
In the context of Linux file system navigation, what is the significance of a pathname that begins with a /
(forward slash)?
In the context of Linux file system navigation, what is the significance of a pathname that begins with a /
(forward slash)?
You encounter an unfamiliar command foo
while working in the Linux CLI. What is the best approach to quickly learn more about its basic usage?
You encounter an unfamiliar command foo
while working in the Linux CLI. What is the best approach to quickly learn more about its basic usage?
What is the primary difference between using semicolons (;
) and the &&
operator to chain commands in a Linux environment?
What is the primary difference between using semicolons (;
) and the &&
operator to chain commands in a Linux environment?
Which command will display the contents of file1.txt
and file2.txt
with line numbers, concatenating them in the output?
Which command will display the contents of file1.txt
and file2.txt
with line numbers, concatenating them in the output?
According to POSIX conventions for command line arguments, which of the following is the correct way to represent multiple single-letter options without arguments?
According to POSIX conventions for command line arguments, which of the following is the correct way to represent multiple single-letter options without arguments?
You want to view the first 20 lines of a file named 'data.log'. Which command would you use?
You want to view the first 20 lines of a file named 'data.log'. Which command would you use?
What will be the output when running ls | cat -n
?
What will be the output when running ls | cat -n
?
Which command would you use to display the content of file1.txt
and file2.txt
on the terminal, concatenating them in the order they are listed?
Which command would you use to display the content of file1.txt
and file2.txt
on the terminal, concatenating them in the order they are listed?
After using the command chmod 640 myfile.txt
, what are the permissions for the group associated with myfile.txt
?
After using the command chmod 640 myfile.txt
, what are the permissions for the group associated with myfile.txt
?
Which command is used to rename a file from oldname.txt
to newname.txt
?
Which command is used to rename a file from oldname.txt
to newname.txt
?
Which command would you use to find the location of the executable file for the command_name
command?
Which command would you use to find the location of the executable file for the command_name
command?
What is the effect of the command rm -r directory_name
?
What is the effect of the command rm -r directory_name
?
If a file has permissions rwxr-x---
, what does the r-x
represent?
If a file has permissions rwxr-x---
, what does the r-x
represent?
What will the following command do: echo "Hello" > file.txt
?
What will the following command do: echo "Hello" > file.txt
?
Which command will show you the current directory you are working in?
Which command will show you the current directory you are working in?
Flashcards
Linux CLI
Linux CLI
Interface for interacting with the Linux OS. Provided by a Linux shell.
help command
help command
Displays information about shell built-in commands.
man command
man command
Displays manuals for commands, system calls, etc.
Pathname
Pathname
Signup and view all the flashcards
Absolute pathname
Absolute pathname
Signup and view all the flashcards
ls command
ls command
Signup and view all the flashcards
cd command
cd command
Signup and view all the flashcards
pwd command
pwd command
Signup and view all the flashcards
mkdir command
mkdir command
Signup and view all the flashcards
echo command
echo command
Signup and view all the flashcards
rm command
rm command
Signup and view all the flashcards
cp command
cp command
Signup and view all the flashcards
cmd < file.txt
cmd < file.txt
Signup and view all the flashcards
cmd1 | cmd2
cmd1 | cmd2
Signup and view all the flashcards
command1 ; command2
command1 ; command2
Signup and view all the flashcards
head
head
Signup and view all the flashcards
cat
cat
Signup and view all the flashcards
Study Notes
- CS 288 Intensive Programming in Linux focuses on the Linux Command Line Interface
Linux Command Line Interface (CLI)
-
The CLI is provided by a Linux shell.
-
The shell is the first thing seen after logging into a server.
-
The shell interacts and runs commands
-
A variety of Linux shells exist, including bash, Bourne Shell (sh), C Shell, and tcsh.
help
command
- The
help
command displays information about shell built-in commands and is useful when writing shell scripts - Typing
"help"
or"help topic"
provides a list or the help page for the specified topic - Typing
"help help"
shows the help page for thehelp
command
man
command
-
A manual displays information about the specified entity
-
man chmod
shows info about the chmod command -
Manual sections include:
-
1: Executable programs or shell commands (e.g.,
man 1 read
) -
2: System calls (functions provided by the kernel) (e.g.,
man 2 read
) -
3: Library calls (functions within program libraries) (e.g.,
man 3 read
) -
4: Special files (usually found in /dev)
-
5: File formats and conventions (e.g., /etc/passwd)
-
Most manuals are available online
File Pathname
- Pathname refers to the location and name of a file.
- Root directory is represented by
/
, current directory by.
, parent directory by..
, and home directory by~
- Absolute pathnames start from the root directory, e.g.,
$ cd /home/CS288/tom
- Relative pathnames are typically related to the current directory, e.g.,
$ cd ./hw/hw1
or$ cd ../hw2
Basic Commands
ls
lists files.cd
changes directoriespwd
shows the current working directorymkdir
makes a directoryecho
displays a line of textcat
concatenates files and prints to standard output (e.g.,$ cat a.txt b.txt
)rmdir
removes a directoryrm
removes files and directories. Userm -r
to remove directories and their contents recursivelymv
moves or renames a filecp
copies a filedate
shows the current timetime
runs a program and reports execution timedu
shows the file size or space consumptionlocate
,whereis
, andwhich
are used to find a file
File and Directory Information
- File and directory information displayed shows:
- type
- permissions
- number of hard links
- name
- size
- user & group
- last time of modification
File System Permissions
- Permissions for files include:
- Read access - read or copy a file
- Write access - write to the file, including deleting the file
- Execute access - execute programs and shell scripts that are text files containing Linux commands
- Permissions for directories include:
- Read access - list the contents of a directory
- Write access - create files
- Execute access - modify file permissions
Linux Permissions
- Permissions are set for the user, group, and others with a single digit from 0-7
- Read = 4
- Write = 2
- Execute = 1
chmod
command
- Use the
chmod
command to set permissions chmod 755 myfile
sets owner to rwx, group to r-x and other to r-x- Owner = 111
- Group = 101
- Other = 101
chmod 540 myfile
sets owner to r-x, group to r--, other to ---- Owner = 101
- Group 100
- Other = 000
chmod 744 myfile
sets owner to rwx, group to r--, other to r--
Redirecting
>
and>>
change the standard output to a file, with>
overwriting and>>
appendingcmd > filename
<
changes the standard input to a commandcmd < file.txt
|
changes standard input and output to another programcmd1 | cmd 2
Multiple Commands
- Commands separated by operators:
;
executes commands sequentially&&
executes the second command only if the first command is successful (returns an exit status of zero).||
executes the second command only if the first command fails (returns a non-zero exit status).
cat
command
- The
cat
command copies the input to output unchanged and concatenates specified file names to stdout -n
numbers output lines starting from 1
Linux Utility Conventions
- POSIX recommends conventions for command-line arguments
- Programs are implemented via
getopt()
man
andhelp
describes command synopses following them- Arguments are options if the begin with a hyphen (
-
) delimiter - Option names are single alphanumeric characters
- Multiple options may follow a hyphen delimiter in a single token if they do not take arguments
head
command
- The
head
command displays the first few lines of a specified file head [-number] [filename...]
-number
sets the number of lines to display, defaulting to 10filename...
is the list of filenames to display- When more than one filename is specified, the start of each file's listing will display the filename
tail
command
- The
tail
command displays the last part of a file tail -n [+|-]number [filename]
tail [+|-]number [filename]
+number
begins copying a the specified number away from the beginning of the file-number, or number
begins from end of file if not specified, thenumber
defaults to 10
cut
Command
- The
cut
command helps to select columns and filter parts of input lines - can select columns
- can select a range of character positions
- Some options include
-f listOfCols
: prints only the specified columns with tab-separated output-c listofPos
: prints only chars in the specified positionsd c
use characterc
as the column separator- Lists are specified as ranges (e.g. 1-5) or comma-separated (e.g. 2,4,5).
paste
Command
- The
paste
command displays multiple text files side by side - If the inputs are files a, b, c, then the first line of output is composed of the respective first lines of a, b, and c
- Each file is separated by a tab character
- If files are a different length, output keeps outputting data from the largest file with empty strings for the smaller files
sort
Command
- The
sort
command copies input and ensures the output is arranged in ascending order of lines - Can sort based on dictionary order or numeric order
- Can specify the key used in the sort with flexibility
- The default key is the entire line
Syntaxes
sort [options] filename
Options-n
Numeric order, sort by arithmetic value-d
Dictionary order-t
Specify delimiter-k
Key-r
Sort in reverse order-o filename
Write output to filename
The -k
Tag
- key: -k [start_position][,stop_position]
start_position
andstop_position
both begin from 1 and are inclusive- If stop_position is omitted, stop_position defaults to line's end by default
- Formation of each position: f[.c][options]
- f is a field number, c is a character position in the field
- options: one or more single-letter ordering options
dictionary? Numeric? Reverse?
override global ordering options
- There can be multiple keys
- 3-k4n
uniq
Command
- The
uniq
command deletes repeated lines in a file uniq [ -cdu] [input-file] [ output-file]
-d
Writes only the duplicated lines-u
Writes only those lines that are not duplicated-c
Supersedes the-u/-d
options and each line in the output is proceded by an occurence count
- The default output is the union (combination) of the command
wc
Command
- The
wc
command counts the number of lines, characters or words - Options:
-l
counts the number of lines-w
counts the number of words-c
counts the number of characters
- The default is to count lines, words and characters
tr
Command
- The
tr
command translates or deletes characters tr [OPTION]... SET1 [SET2]
performs text transformations, such as uppercase to lowercase, repeat squeezing, deleting specific characters, find and replacing characters-c
first complement SET1-d
deletes characters-s
squeezes repeats
Vi Editor
- Vi editor is fast and easy
- Basic modes are edit and command
- 'esc' is used for command mode
- 'i, a' is used for edit mode (insert or append mode)
- Other commands used with colon- :q,:w,:q!,:e
:q
quits:w
writeq!
quits without saving:e
open another file for editing:wq
write and quit
- Searching uses '/'
- In command mode, '/' finds the specified word you want to search
- Press
n
for forward search andN
for backward search
- A specific line can be jumped to by typing the line number followed by shift + G
- Search and replace by typing
:%s/this/that - will search string "this" and replace with 'that'
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.