Linux Command Line Interface - CS 288
Document Details

Uploaded by SmarterPoplar1113
NJIT
Tags
Related
- The Linux Command Line_ Your Path to Faster Computing_ Unleash Linux's Potential for Beginners and Experienced Users_compressed.pdf
- Linux Command Line Basics PDF
- Linux Command Line Tutorial PDF
- System Administration - Linux PDF
- Exploring Linux Command-Line Tools PDF
- Chapter 1: Introduction to Linux PDF
Summary
This presentation introduces the Linux Command Line Interface (CLI), a fundamental skill for programmers. It covers essential commands for file and directory management, including permissions, redirection, and filtering. The content is designed for an intensive programming course, highlighting the importance of the CLI for efficient coding.
Full Transcript
CS 288 Intensive Programming in Linux Linux Command Line Interface Linux command line interface (CLI) CLI is provided by a Linux shell – The first thing you see after you log into the server. – Interact with you and run your commands. A variety of Linux shells are avail...
CS 288 Intensive Programming in Linux Linux Command Line Interface Linux command line interface (CLI) CLI is provided by a Linux shell – The first thing you see after you log into the server. – Interact with you and run your commands. A variety of Linux shells are available – bash, Bourne Shell (sh), C Shell, tcsh, You must know how to use help command help command displays information about shell built- in commands. It is also useful when writing a shell script. “help” or “help topic” – “help” prints the list – “help topic” prints the help page of the topic. what is “help help”? – Help page of the “help” command. You must know how to use man command e.g., man chmod man [section #] topic – 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 eg /etc/passwd – … Most manuals can be found online File Pathname: location pathname and name of the file. Remember root is /, current directory (current working directory, pwd) is., parent directory is.., home directory is ~ Absolution pathnames start from root. $ cd /home/CS288/tom Relative pathnames are usually relative to the current directory. $ cd./hw/hw1 $ cd../hw2 Some ls – list files commands $ ls /home/john cd – change directory $ cd /tmp pwd – current working directory mkdir – create a directory $ mkdir /home/alice/proj1 echo- display a line of text $ echo "hello world" cat - concatenate files and print on the standard output $ cat a.txt b.txt Some rmdir – remove a commands directory $ rmdir /home/tom/tmp rm – remove a file/files – remove directories and their contents recursively: $ rm –r mv – move or rename a file $ mv /etc/ftpaccess /var/ftp/ftpaccess cp – copy a file $ cp var/ftp/ftpaccess /home/amy/ date -- current time time --- run program and report execution time $ time ls /usr/bin du – file size/space consumption $ du -b /home/amy/hw1 locate, whereis, which – find a file $ locate ftpaccess File and directory information typ # of hard linkssiz e name e permissio ns user & group lasttim modification nam e File system permissions in Permission Linux When used with files When used with type directories Read Read a file or copy a file List the contents of a directory Write Write to the file, including deleting Create files the file Execute Execute programs and shell scripts, Modify the file permissions which are text files containing Linux commands Linux Permissions Permissions are set for user, group, and others Each permission is set with a single digit from 0 to 7 based on the combination of permissions – read = 4 – write = 2 othe – execute rs =1 grou p user Using chmod to Set Permissions Command Permissions Owner Group Other chmod 755 myfile rwx r-x r-x 111 101 10 1 chmod 540 myfile r-x r— --- 101 100 00 0 chmod 744 myfile rwx r-- r-- Redirecting (>, Using > and>>, >> to filename – > overwrite, >> append Using < to change standard input to a command. – cmd < file.txt Using | to change standard input and standard output to another program – cmd1 | cmd 2 Difference from wring multiple commands on the same line. List of commands Multiple commands separated by operators command1 ; command2 : execute one after another. command1 && command2 : AND list. Command2 is executed if, and only if, command1 returns an exit status of zero (success) command1 || command2 : OR list. command2 is executed if, and only if, command1 returns a non-zero exit status. cat: the simplest filter The cat command copies its input to output unchanged (identity filter). When supplied a list of file names, it concatenates them onto stdout. Some options: – -n number output lines (starting from 1) cat file* ls | cat -n Linux utility conventions POSIX recommends some conventions for command line arguments. – Programs implement them. getopt() makes it easy. – man and help describes command synopses following them (e.g., help cd). – https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html utility_name [-a] [-b] [-c option_arg] [-d|-e] [-f [option_arg]] [operand...] Arguments are options if they begin with a hyphen delimiter (‘-’). – Option names are single alphanumeric characters – Multiple options may follow a hyphen delimiter in a single token if the options do not take arguments. Thus, ‘-abc’ is equivalent to ‘-a -b -c’. hea d Display the first few lines of a specified file Syntax: head [-number] [filename...] – -number - number of lines to display, default is 10 – filename... - list of filenames to display When more than one filename is specified, the start of each files listing displays the filename as follows: ==>filename