Untitled

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

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?

  • $ cd /
  • $ cd .
  • $ cd ..
  • $ cd ~ (correct)

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)?

<p>The pathname represents an absolute path starting from the root directory. (D)</p> Signup and view all the answers

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?

<p>Executing <code>help foo</code> to view built-in help information. (B)</p> Signup and view all the answers

What is the primary difference between using semicolons (;) and the && operator to chain commands in a Linux environment?

<p>Semicolons execute each command regardless of the success of the previous command, while <code>&amp;&amp;</code> only executes the next command if the previous one succeeds. (D)</p> Signup and view all the answers

Which command will display the contents of file1.txt and file2.txt with line numbers, concatenating them in the output?

<p><code>cat -n file1.txt file2.txt</code> (C)</p> Signup and view all the answers

According to POSIX conventions for command line arguments, which of the following is the correct way to represent multiple single-letter options without arguments?

<p><code>command -abc</code> (A)</p> Signup and view all the answers

You want to view the first 20 lines of a file named 'data.log'. Which command would you use?

<p><code>head -20 data.log</code> (C)</p> Signup and view all the answers

What will be the output when running ls | cat -n?

<p>The command will list files and directories in the current directory with each line numbered. (C)</p> Signup and view all the answers

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?

<p><code>cat file1.txt file2.txt</code> (A)</p> Signup and view all the answers

After using the command chmod 640 myfile.txt, what are the permissions for the group associated with myfile.txt?

<p>Read only (A)</p> Signup and view all the answers

Which command is used to rename a file from oldname.txt to newname.txt?

<p><code>mv oldname.txt newname.txt</code> (C)</p> Signup and view all the answers

Which command would you use to find the location of the executable file for the command_name command?

<p><code>which command_name</code> (B)</p> Signup and view all the answers

What is the effect of the command rm -r directory_name?

<p>It removes the directory and all its contents recursively. (A)</p> Signup and view all the answers

If a file has permissions rwxr-x---, what does the r-x represent?

<p>Permissions for the group associated with the file. (B)</p> Signup and view all the answers

What will the following command do: echo "Hello" > file.txt?

<p>Overwrite <code>file.txt</code> with the word 'Hello' (B)</p> Signup and view all the answers

Which command will show you the current directory you are working in?

<p><code>pwd</code> (D)</p> Signup and view all the answers

Flashcards

Linux CLI

Interface for interacting with the Linux OS. Provided by a Linux shell.

help command

Displays information about shell built-in commands.

man command

Displays manuals for commands, system calls, etc.

Pathname

The location and name of a file in the file system

Signup and view all the flashcards

Absolute pathname

Full path from the root directory.

Signup and view all the flashcards

ls command

Lists files and directories in the current directory.

Signup and view all the flashcards

cd command

Changes the current directory.

Signup and view all the flashcards

pwd command

Prints the current working directory.

Signup and view all the flashcards

mkdir command

Creates a new directory.

Signup and view all the flashcards

echo command

Displays a line of text.

Signup and view all the flashcards

rm command

Removes a file or directory. Use -r for recursive directory removal.

Signup and view all the flashcards

cp command

Copies a file.

Signup and view all the flashcards

cmd < file.txt

Redirects standard input from a file.

Signup and view all the flashcards

cmd1 | cmd2

Connects the standard output of one command to the standard input of another.

Signup and view all the flashcards

command1 ; command2

Executes commands one after another, regardless of the success of the previous command.

Signup and view all the flashcards

head

Displays the beginning of a file.

Signup and view all the flashcards

cat

Copies input to output, concatenating files.

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 the help 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 directories
  • pwd shows the current working directory
  • mkdir makes a directory
  • echo displays a line of text
  • cat concatenates files and prints to standard output (e.g., $ cat a.txt b.txt)
  • rmdir removes a directory
  • rm removes files and directories. Use rm -r to remove directories and their contents recursively
  • mv moves or renames a file
  • cp copies a file
  • date shows the current time
  • time runs a program and reports execution time
  • du shows the file size or space consumption
  • locate, whereis, and which 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 >> appending
  • cmd > filename
  • < changes the standard input to a command
  • cmd < file.txt
  • | changes standard input and output to another program
  • cmd1 | 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 and help 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 10
  • filename... 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, the number 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 positions
  • d c use character c 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 and stop_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 write
    • q! 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 and N 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.

Quiz Team

Related Documents

More Like This

Untitled
110 questions

Untitled

ComfortingAquamarine avatar
ComfortingAquamarine
Untitled
44 questions

Untitled

ExaltingAndradite avatar
ExaltingAndradite
Untitled
6 questions

Untitled

StrikingParadise avatar
StrikingParadise
Untitled
49 questions

Untitled

MesmerizedJupiter avatar
MesmerizedJupiter
Use Quizgecko on...
Browser
Browser