file commands

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

crontab options

crontab -r #Remove the current crontab crontab -l #Display current crontab crontab -u #Append the name of the user whos crontab is to be edited

mv command options

-b #Make a backup of the existing file before it is overwritten; creates backup file with ~ extended to it -f, --force #Do not prompt before overwriting -i, --interactive #Prompt before overwriting -n, --no-clobber #Do not overwrite any existing file --strip-trailing-slashes #Remove any trailing slashes from each SOURCE argument -S, --suffix=SUFFIX #Use the suffix SUFFIX for all backup files. The default SUFFIX is "~". -t, --target-directory=DIRECTORY #Move all SOURCE arguments into directory DIRECTORY. -T, --no-target-directory #Treat DEST as a normal file, not as a directory. -u, --update #Perform the move only if the SOURCE file is newer than the destination file, or the destination file does not already exist.

more command options

-num n #Set the number of lines, n, that make up a screenful +/string #Search for the string called string, and advance to the first line containing string when the file is displayed +num #Start displaying text at line number num

kill command signals

1 #"Hang-up" 2 #Interrupt 3 #Quit 6 #Abort 9 #Kill, terminates a process right away without saving and cannot be ignored 15 #Term, tries to terminate the process; safest way

Hard Link

A file in the file system is basically a link to an inode; a hard link creates another file with the same link to the inode When a file is deleted, it removes a link to the inode; the inode is only deleted when all links are removed Deleting, renaming, or moving the file will not affect the hard link because it links to the underlying node; any changes to the data in the node is reflected in all links to the node Basically, doesnt link to another file like a symbolic link

Symbolic Link

Basically a link to a link; if file2.txt is linked to file1.txt, it does not point to the contents of file1.txt, but points to file1.txt Can link to directories Can cross file system boundaries, so a symbolic to data on one drive or partition can exist on another drive or partition If the linked to file is removed, the symbolic link can no longer access the contents; it points to something that no longer exists Useful to create a symbolic link if the directory name is a long path

find command

Can be used to find files and directories and perform subsequent actions on them; can search by file, folder, name, creation date, modification date, owner and permissions Syntax: find startDest [options] fileName find startDest [options] fileName [options]

chgrp command

Changes group ownership of a file or file(s) Syntax: chgrp [option] GROUP file chgrp hope file.txt #Change the owning group of file.txt to hope

chmod command

Changes permissions of a file 3 sets of permissions: u for user, g for the owner's group, and o for other Permissions: r for read, w for write, x for execute Operators: = set the permissions, + add permissions, - take away permissions Syntax: chmod [u, g, or o] [operator] [any set of rwx] file(s) chmod never changes permissions of symbolic links ex. chmod u-w file1.c #Takes away user permissions for writing ex. chmod o=rx $turnin/x.y #Make other have read and execute permissions on x.y ex. chmod u=,g=rx,o=r file1.c #Takes away all user permissions, gives group read and execute, gives other read

cd command

Changes the shell's current working directory Current directory is represented as a '.' The root directory is represented as '/' The parent directory of the current directory is represented as '..' The home directory is represented as '~' Syntax: cd [options] dirName

chown command

Changes the user and/or group ownership of each given file If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the files' group is not changed If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well If a colon but no group name follows the user name, that user is made the owner of the files and the group of the files is changed to that user's login group If the colon and group are given, but the owner is omitted, only the group of the files is changed If only a colon is given, or if the entire operand is empty, neither the owner nor the group is changed Syntax: chown [options] [owner][:[group]] file Option: --from=CURRENT_OWNER:CURRENT_GROUP #Change the owner and/or group of each file only if its current owner and/or group match those specified here; either may be omitted, in which case a match is not required for the omitted attribute

paste command

Create a file with columns from the contents of a set of files, writes lines consisting of the sequentially corresponding lines from each file (separated by tabs); sent to standard output Syntax: paste [option] FILE(s)

mkdir command

Creates a directory, if the specified directory does not already exist More than one directory may be specified Syntax: mkdir [option] directoryName

ln command

Creates a link to the targeted file with the specified name; essentially a second name to the file, in which two file names point to the same file If the linkname is ommitted, a link to the targeted file is created in the current directory, using the targeted file's name as the linkname Creates hard links by default; when creating hard links, the target file MUST exist Syntax: ln fileName linkName

cut command

Cuts sections from each line of files and writes the result to standard output; can be used to cut parts of a line by byte position, delimiter, or character Syntax: cut [option] file

ps command

Displays active processes, outputs to standard output Operating system demand, as it relies on the operating system internals for how processing and execution tools are being managed Syntax: ps [options] If just ps, outputs as follows: PID TTY TIME CMD 578 pts/3 00:00:00 zsh PID - the number of the process TTY - the name of the console the user is logged into TIME - the amount of CPU in minutes and seconds the process has been running CMD - The name of the command that launched the process

more command

Displays text one screen at a time Syntax: more [options] [-num lines] [+/pattern] [+linenum] file

adding commands to crontab

First, must do crontab -e First five pieces of information: Numbers can also be in a list or range; names can also be a list 1. A number, m, representing the minute of the hour 2. A number, h, representing the hour of the day 3. A number, dom, representing the day of the month 4. A number or name, mon, representing the month of the year 5. A number or name, dow, representing the day of the year If an * is given for any of these 5 pieces of info, it means 'every' After this, give the command to be run, exactly as it would appear on the command line ex. 0 2 9 5 /home/name/user/scripts/do-everyday.sh #At 2am, on the 9th of may, execute do-everyday.sh

ls command

Lists directory contents of files and directories Syntax: ls [options] file ls [options] directory

wc command

Prints a count of newlines, words, and bytes for each input file, and a total if more than one file is specified Counts are always in this order: newline, word, character, byte Syntax: wc [option] file Options: wc -c file #Print the byte counts wc -m file #Print the character counts wc -l file #Print the newline counts wc -L file #Print the length of the longest line wc -w file #Print the word counts

cat command

Reads data from a file or file(s) and outputs their contents to standard output Primarily used to display text files, copy text files into a new document, append the contents of a text file to the end of another text file (combining them), and to create new text files Syntax: cat [option] file cat file1.txt file2.txt #Prints the contents of both files, as if they were a single copy cat file1.txt > file2.txt #Overwrites the contents of file2.txt with the contents of file1.txt; if file2.txt does not exist, it is created cat file1.txt file2.txt > file3.txt #Same as above but with two files cat file1.txt >> file2.txt #Appends the contents of file1.txt to the end of file2.txt echo "My shopping list" | cat - list.txt #Adds the text "My shopping list" to the beginning of list.txt

rmdir command

Removes a directory, if the directory is empty Arguments are processed in the order given; to delete a parent directory and a subdirectory, the subdirectory must be removed first, so the parent directory is empty when it is removed Syntax: rmdir directoryName OR rmdir -p directoryName #Each directory argument is treated as a pathname in which all components are to be removed, if they are empty, starting with the last component

rm command

Removes each specified file; by default, does not remove directories Unlinks a file name in a file system from data on the storage device, and marks it as usable for future writes; increases amount of available space Syntax: rm [options] file #To remove directories and their contents recursively, use rm -r OR rm -R

pwd command

Reports the full path to the current directory (the directory the user is currently operating while using a command line interface) Syntax: pwd [option]

crontab command

Schedules periodic events, such as a program that executes commands at particular times; designed for commands done regularly or periodically The program, crontab, allows you to edit the schedule of the system process cron To edit: crontab -e

kill command

Sends a signal to a process Syntax: kill -N PID #Where N is a signal number

sort command

Sorts the contents of a set of TEXT files By default case-sensitive and alphabetical Syntax: sort [options] filename ex. sort band.txt #Sorts the band.txt file alphabetically line by line and writes this to standard output

tar command functions

Specifies what the main operation of the tar command will be; the function LETTER does not need to be prefixed with a dash '-' A #append files to an archive c #create a new archive r #Append files to the end of an archive t #list the contents of an archive x #extract files from the archive

tar command options

Specify the way tar operates -f #Specifies the output file; indicates what the preceding operation will be operated on ex. tar cf archive.tar file1 file2 #Creates an archive, archive.tar, which contains file1 & file2. c specifies that tar will be creating an archive, and f specifies that the next option will be the archive it creates

spell command

Spell checking program that scans a text file for misspelled words, and prints each misspelled word on its own line Syntax: spell [options] file.txt spell -b #Use british dictionary spell -d FILE #Treat FILE as a dictionary spell -n #Print line numbers & for each mispelled word, print the line it is located in

mv command

Take a file(s) or a directory & a destination & moves them to the destination, OR renames them Syntax: mv [options] -T SOURCE DESTINATION mv [options] SOURCE DIRECTORY mv [options] -t DIRECTORY SOURCE ex. mv foo.txt bar.txt #foo.txt is renamed to bar.txt; bar.txt is overwritten ex. mv foo.txt bar #foo.txt is moved into the directory bar ex. mv text1.txt text2.txt text3.text folder #moves all three text files to the destination folder ex. mv *.txt folder #moves all .txt files to the destination folder ex. mv foo bar #moves the foo directory into the bar directory

cp command

Takes a file(s) or directory and a destination and copies them Syntax: cp [options] source destination cp source destination cp source directory cp file1 file2 cp file1 new-file2 cp [options] file1 new-file2 Files copied will have the same name as original cp main.c bak #Copy main.c to bak directory cp main.c home.c /home/usr/rapid #Copy the two files main.c and home.c to the directory location cp *.c bak #Copy all .c files to bak directory cp -r rev dev #Copy all files and directories in directory rev recurisvely to the subdirectory dev

tar command

Used to create, maintain, modify and extract files that are archived in the tar format Commonly used to combine files into a single file for easy storage and distribution Syntax: tar functionspecification [options] archiveFile.tar file(s)

cat command options

cat -b #Number non-empty output lines cat -n #Number all output lines cat -E #Display $ at the end of each line

cd command options

cd -L #Forces symbolic links to be followed, so if the argument is a symbolic link to a directory, goes to the directory the link is pointing to cd -P #Do not follow symbolic links

cp options

cp -a #archive files cp -f #force copy by removing the destination file if needed cp -i #interactive - ask before overwrite cp -l #link files instead of copy cp -L #follow symbolic links cp -n #no file overwrite cp -R #recursive copy (including hidden files) cp -u #update - copy when source is newer than dest

cut command options

cut -c #Cut by character, selects the characters given; can be a list of comma separated numbers, a range of numbers, or a single number cut -d #Cuts by a delimiter cut -f #Cuts by field; usually used with -d ex. echo DaisiesP | cut -c 1,6 #Outputs De ex. echo DaisiesP | cut -c 1-3 #Outputs Dai ex. cut -d ',' -f1 textFile.txt #Outputs the first field of each line in the text file, and is delimited by a comma

find command options

find /dir -atime n #Find the file in the directory dir that was accessed n days ago find /dir -mtime n #Find the file in the directory dir that was modified n days ago find /dir -size n #Find file in the directory dir with specified size n find /dir -type d #Find a directory in the directory dir find /dir -type f #Find a regular file in the directory dir find /dir -name fileName #Find a file, named fileName, in the directory dir ex. find /dir -type f -name bar -exec [command] {} \; #Find the file named bar in the directory dir, and execute a command on it; have to include {} \; at the end of the command ex. find ./foo -mtime -1 #Finds the file(s) in the directory dir that were modified less than a day ago ex. find ./foo -name foo.txt --delete #Find the file foo.txt in the directory dir, and delete it

head command and tail command

head #Prints the first 10 lines of each file to standard output tail #Prints the last 10 lines of the contents of each file If more than one file is specified, it precedes each line of output with a header identifying the file name If no file specified or just a dash specified, it will read from standard input Syntax: head [option] file tail [option] file Options: head -n n file #Print the first n lines head -q file(s) #Do not print headers tail -n n file #Print the last n lines tail -q file(s) #Do not print headers

ln command options

ln -s file1 file2 #Creates a symbolic link to file1 named file2 (can also be done with directories)

ls command options

ls -a #List all files, including hidden files starting with '.' ls -d #Lists directories ls -l #Long listing, shows permissions ls -r #List in reverse order ls -s #List file size ls -S #Sort by file size ls -t #Sort by time and date ls -X #Sort by extension name ex. ls -d $PWD/* #List files and directories by full path

mkdir command options

mkdir -m [ugo] [operator] dirName #Creates a directory and specifies the permissions mkdir -p dirName #Creates necessary parent directories ex. mkdir -p user/files/a/b #Creates the directory user/files/a if it does not exist, and creates the directory user/files/a/b

paste command options

paste -d #Specifies a delimiter, which replaces the tab default separation paste -s #Paste one file at a time ex. paste -d'|,' file1.txt file2.txt file3.txt #Outputs the lines of each file, with the contents of file1 and file2 separated by a | and the contents of file2 and file3 separated by ,

ps command options

ps -a #Displays all processes on a terminal ps -c #Displays scheduler data ps -e #Specifies ALL the processes ps -u #Displays data for the list of usernames; default is you ps -f #Displays a full listing ps -p #List all processes by process number ex. ps -u tocheym //Process of the user tocheym ex. ps -p 1546 #Lists the PID, TTY, STAT, TIME, AND CMD for the specified process(es)

pwd command options

pwd -L #Print the full path, even if it contains symbolic links pwd -P #Print the full path with actual directories and no symbolic links

sort command options

sort -r #sorts in reverse order sort -n #sorts by number, from lowest number to highest number sort -f #sorts mixed-case text; ignores case sensitivity; by default sorts uppercase first sort -c #check if a file is already sorted sort -u #Sorts the file and removes duplicates sort -k n #Sorts by items not at the beginning of the line, where n specifies the field to be sorted by sort -o file1.txt file2.txt #Specifies an output file, where the sorted contents of file2.txt are stored in and overwrite file1.txt


Ensembles d'études connexes

Maternity and Women's Health- Pregnancy, Uncomplicated

View Set

Upper Limb Questions (Chapter 6)

View Set

Clinical Microbiology Exam 1 (CH 9)

View Set