Linux Commands

¡Supera tus tareas y exámenes ahora con Quizwiz!

ls /usr

Besides the current working directory, we can specify the directory to list.

cd -

Changes the working directory to the previous working directory.

exit

End a terminal session.

ls

List directory contents. Actually, we can use the ls command to list the contents of any directory, not just the current working directory, and there are many other fun things it can do as well.

mkdir - Create Directories

The mkdir command is used to create directories. It works like this: mkdir directory... A note on notation: When three periods follow an argument in the description of a command (as above), it means that the argument can be repeated, thus the following command: mkdir dir1 dir2 dir3 would create three directories named dir1, dir2, and dir3.

rm - Remove Files and Directories

The rm command is used to remove (delete) files and directories, as shown here: rm item... where item is one or more files or directories.

ls -alt --reverse

a : list ALL files l: display results in long format t: sort by modification time reverse: reverse the order of the sort

help - Get Help for Shell Builtins

bash has a built-in help facility available for each of the shell builtins. To use it, type "help" followed by the name of the shell builtin. Here is an example: help cd

Playground exercise

cd mkdir playground cd playground mkdir dir1 dir2 cp /etc/passwd . ls -l cp -v /etc/passwd . cp -i /etc/passwd . mv passwd fun mv fun dir1 mv dir1/fun dir2 mv dir2/fun . mv fun dir1 mv dir1 dir2 ls -l dir2 ls -l dir2/dir1 mv dir2/dir1 . mv dir1/fun . ln fun fun-hard ln fun dir1/fun-hard ln fun dir2/fun-hard ls -l ls -li ln -s fun fun-sym ln -s ../fun dir1/fun-sym ln -s ../fun dir2/fun-sym ls -l dir1 ln -s dir1 dir1-sym ls -l rm fun-hard ls -l rm -i fun ls -l rm fun-sym dir1-sym ls -l cd rm -r playground

free

Display the amount of free memory.

info - Display a Program's Info Entry

Info manuals are displayed with a reader program named, appropriately enough, info. Info pages are hyperlinked much like web pages. Info files contain hyperlinks that can move the reader from node to node. A hyperlink can be identified by its leading asterisk and is activated by placing the cursor upon it and pressing the Enter key. To invoke info, type info followed optionally by the name of a program. Most of the command line programs we have discussed so far are part of the GNU Project's coreutils package, so typing the following: info coreutils

rm Examples

rm file1 - Delete file1 silently. rm -i file1 - Same as the previous command, except that the user is prompted for confirmation before the deletion is performed. rm -r file1 dir1 - Delete file1 and dir1 and its contents. rm -rf file1 dir1 - Same as the previous command, except that if either file1 or dir1 do not exist, rm will continue silently.

man - Display a Program's Manual Page

Most executable programs intended for command line use provide a formal piece of documentation called a manual or man page. man program where "program" is the name of the command to view. man ls Sometimes we need to refer to a specific section of the manual to find what we are looking for. This is particularly true if we are looking for a file format that is also the name of a command. Without specifying a section number, we will always get the first instance of a match, probably in section 1. To specify a section number, we use man like this: man section search_term man 5 passwd This will display the man page describing the file format of the /etc/passwd file. man bash

Wildcare examples

* - All files g* - Any file beginning with "g" b*.txt - Any file beginning with "b" followed by any characters and ending with ".txt" Data??? - Any file beginning with "Data" followed by exactly three characters [abc]* - Any file beginning with either an "a", a "b", or a "c" BACKUP.[0-9][0-9][0-9] - Any file beginning with "BACKUP." followed by exactly three numerals [[:upper:]]* - Any file beginning with an uppercase letter [![:digit:]]* - Any file not beginning with a numeral *[[:lower:]123] - Any file ending with a lowercase letter or the numerals "1", "2", or "3"

File names Important Facts

- Filenames that begin with a period character are hidden. This only means that ls will not list them unless you say ls -a. When your account was created, several hidden files were placed in your home directory to configure things for your account. - Filenames and commands in Linux, like Unix, are case sensitive. The filenames "File1" and "file1" refer to different files. - Linux has no concept of a "file extension" like some other operating systems. You may name files any way you like. The contents and/or purpose of a file is determined by other means. - Though Linux supports long filenames that may contain embedded spaces and punctuation characters, limit the punctuation characters in the names of files you create to period, dash, and underscore. Most importantly, do not embed spaces in filenames. If you want to represent spaces between words in a filename, use underscore characters.

rm Options

-i / --interactive / Before deleting an existing file, prompt the user for confirmation. If this option is not specified, rm will silently delete files. -r / --recursive / Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified. -f / --force / Ignore nonexistent files and do not prompt. This overrides the --interactive option. -v / --verbose / Display informative messages as the deletion is performed.

Directories found on linux pt 2

/opt /The /opt directory is used to install "optional" software. This is mainly used to hold commercial software products that might be installed on the system. /proc /The /proc directory is special. It's not a real file system in the sense of files stored on the hard drive. Rather, it is a virtual file system maintained by the Linux kernel. The "files" it contains are peepholes into the kernel itself. The files are readable and will give us a picture of how the kernel sees the computer. /root /This is the home directory for the root account. /sbin /This directory contains "system" binaries. These are programs that perform vital system tasks that are generally reserved for the superuser. /tmp /The /tmp directory is intended for the storage of temporary, transient files created by various programs. Some configurations cause this directory to be emptied each time the system is rebooted. /usr /It is likely the largest one on a Linux system. It contains all the programs and support files used by regular users. /usr/bin /contains the executable programs installed by the Linux distribution. It is not uncommon for this directory to hold thousands of programs. /usr/lib /The shared libraries for the programs in /usr/bin. /usr/local /It is where programs that are not included with the distribution but are intended for systemwide use are installed. Programs compiled from source code are normally installed in /usr/local/bin. On a newly installed Linux system, this tree exists, but it will be empty until the system administrator puts something in it. /usr/sbin /Contains more system administration programs. /usr/share /contains all the shared data used by programs in /usr/bin. This includes things such as default configuration files, icons, screen backgrounds, sound files, etc. /usr/share/doc /Most packages installed on the system will include some kind of documentation. In /usr/share/doc, we will find documentation files organized by package. /var /With the exception of /tmp and /home, the directories we have looked at so far remain relatively static, that is, their contents don't change. The /var directory tree is where data that is likely to change is stored. Various databases, spool files, user mail, etc. are located here. /var/log /contains log files, records of various system activity. These are important and should be monitored from time to time. The most useful ones are /var/log/messages and /var/log/syslog. Note that for security reasons on some systems only the superuser may view log files.

What exactly are commands?

1. An executable program like all those files we saw in /usr/bin. Within this category, programs can be compiled binaries such as programs written in C and C++, or programs written in scripting languages such as the shell, Perl, Python, Ruby, and so on. 2. A command built into the shell itself. bash supports a number of commands internally called shell builtins. The cd command, for example, is a shell builtin. 3. A shell function. Shell functions are miniature shell scripts incorporated into the environment. We will cover configuring the environment and writing shell functions in later chapters, but for now, just be aware that they exist. 4. An alias. Aliases are commands that we can define ourselves, built from other commands.

Absolute pathnames

An absolute pathname begins with the root directory and follows the tree branch by branch until the path to the desired directory or file is completed. For example, there is a directory on our system in which most of our system's programs are installed. The directory's pathname is /usr/bin. This means from the root directory (represented by the leading slash in the pathname) there is a directory called "usr" which contains a directory called "bin".

Exploring the system steps

1. cd into a given directory 2. List the directory contents with ls -l 3. If you see an interesting file, determine its contents with file 4. If it looks like it might be text, try viewing it with less 5. If we accidentally attempt to view a non-text file and it scrambles the terminal window, we can recover by entering the reset command.

ls -l -a

By adding "-l" to the command, we changed the output to the long format.

cd

Change directory. To change our working directory (where we are standing in our tree-shaped maze) we use the cd command. To do this, type cd followed by the pathname of the desired working directory. A pathname is the route we take along the branches of the tree to get to the directory we want. We can specify pathnames in one of two different ways; as absolute pathnames or as relative pathnames.

cd ~user_name

Changes the working directory to the home directory of user_name. For example, cd ~bob will change the directory to the home directory of user "bob."

cd

Changes the working directory to your home directory.

Info Commands

Command / Action ? / Display command help PgUp or Backspace / Display previous page PgDn or Space / Display next page n / Next - Display the next node p / Previous - Display the previous node u / Up - Display the parent node of the currently displayed node, usually a menu Enter / Follow the hyperlink at the cursor location q / quit

Most common commands used by less

Command /Action Page Up or b /Scroll back one page Page Down or space /Scroll forward one page Up arrow /Scroll up one line Down arrow /Scroll down one line G /Move to the end of the text file 1G or g /Move to the beginning of the text file /characters /Search forward to the next occurrence of characters n /Search for the next occurrence of the previous search h /Display help screen and SUMMARY OF LESS COMMANDS q /Quit less

Commands, Options and Arguments

Commands are often followed by one or more options that modify their behavior, and further, by one or more arguments, the items upon which the command acts. So most commands look kind of like this: command -options arguments. Most commands use options which consist of a single character preceded by a dash, for example, "-l". Many commands, however, including those from the GNU Project, also support long options, consisting of a word preceded by two dashes. Also, many commands allow multiple short options to be strung together. In the following example, the ls command is given two options, which are the l option to produce long format output, and the t option to sort the result by the file's modification time. We'll add the long option "--reverse" to reverse the order of the sort. ls -lt --reverse

file

Determine file type. As we explore the system it will be useful to know what files contain. To do this we will use the file command to determine a file's type. As we discussed earlier, filenames in Linux are not required to reflect a file's contents. While a filename like "picture.jpg" would normally be expected to contain a JPEG compressed image, it is not required to in Linux. file filename. When invoked, the file command will print a brief description of the file's contents. ex: file .profile

Directories found on linux

Directories /Comments / /The root directory. Where everything begins. /bin /Contains binaries (programs) that must be present for the system to boot and run. /boot /Contains the Linux kernel, initial RAM disk image (for drivers needed at boot time), and the boot loader. Interesting files: ● /boot/grub/grub.conf or menu.lst, which are used to configure the boot loader. ● /boot/vmlinuz (or something similar), the Linux kernel /dev /This is a special directory that contains device nodes. "Everything is a file" also applies to devices. Here is where the kernel maintains a list of all the devices it understands. /etc /The /etc directory contains all of the system-wide configuration files. It also contains a collection of shell scripts that start each of the system services at boot time. Everything in this directory should be readable text. Interesting files: While everything in /etc is interesting, here are some all-time favorites: ● /etc/crontab, a file that defines when automated jobs will run. ● /etc/fstab, a table of storage devices and their associated mount points. ● /etc/passwd, a list of the user accounts. /home /In normal configurations, each user is given a directory in /home. Ordinary users can only write files in their home directories. This limitation protects the system from errant user activity. /lib /Contains shared library files used by the core system programs. These are similar to dynamic link libraries (DLLs) in Windows. /lost+found /Each formatted partition or device using a Linux file system, such as ext4, will have this directory. It is used in the case of a partial recovery from a file system corruption event. Unless something really bad has happened to our system, this directory will remain empty. /media /On modern Linux systems the /media directory will contain the mount points for removable media such as USB drives, CD-ROMs, etc. that are mounted automatically at insertion. /mnt /On older Linux systems, the /mnt directory contains mount points for removable devices that have been mounted manually.

cal

Displays a calendar of the current month.

df

Displays current amount of free space on our disk drives.

date

Displays the current time and date.

How to read the long format ls -l

Field/meaning -rw-r--r-- / Access rights to the file. The first character indicates the type of file. Among the different types, a leading dash means a regular file, while a "d" indicates a directory. The next three characters are the access rights for the file's owner, the next three are for members of the file's group, and the final three are for everyone else. 1 /File's number of hard links. See the sections "Symbolic Links" and "Hard Links" later in this chapter. root /The username of the file's owner. root /The name of the group that owns the file. 32059 /Size of the file in bytes. 2007-04-03 11:05 /Date and time of the file's last modification. oo-cd-cover.odf /Name of the file. PS: numbers, date, and name of the file is just an example.

Hard Links

Hard links are the original Unix way of creating links, compared to symbolic links, which are more modern. By default, every file has a single hard link that gives the file its name. When we create a hard link, we create an additional directory entry for a file. Hard links have two important limitations: 1. A hard link cannot reference a file outside its own file system. This means a link cannot reference a file that is not on the same disk partition as the link itself. 2. A hard link may not reference a directory. A hard link is indistinguishable from the file itself. Unlike a symbolic link, when we list a directory containing a hard link we will see no special indication of the link. When a hard link is deleted, the link is removed but the contents of the file itself continue to exist (that is, its space is not deallocated) until all links to the file are deleted. It is important to be aware of hard links because you might encounter them from time to time, but modern practice prefers symbolic links.

I/O redirection

I/O redirection allows us to change where output goes and where input comes from. Normally, output goes to the screen and input comes from the keyboard, but with I/O redirection, we can change that.

Redirecting Standard Output

I/O redirection allows us to redefine where standard output goes. To redirect standard output to another file instead of the screen, we use the > redirection operator followed by the name of the file. For example, we could tell the shell to send the output of the ls command to the file ls-output.txt instead of the screen: ls -l /usr/bin > ls-output.txt ls -l ls-output.txt less ls-output.txt ls -l /bin/usr > ls-output.txt (directory does not exist) The ls program does not send its error messages to standard output. Instead, like most well-written Unix programs, it sends its error messages to standard error. Since we only redirected standard output and not standard error, the error message was still sent to the screen. ls -l ls-output.txt The file now has zero length! This is because when we redirect output with the ">" redirection operator, the destination file is always rewritten from the beginning. Since our ls command generated no results and only an error message, the redirection operation started to rewrite the file and then stopped because of the error, resulting in its truncation. In fact, if we ever need to actually truncate a file (or create a new, empty file), we can use a trick like > ls-output.txt Simply using the redirection operator with no command preceding it will truncate an existing file or create a new, empty file. So, how can we append redirected output to a file instead of overwriting the file from the beginning? For that, we use the >> redirection operator, like so: ls -l /usr/bin >> ls-output.txt Using the >> operator will result in the output being appended to the file. If the file does not already exist, it is created just as though the > operator had been used.

apropos - Display Appropriate Commands

It is also possible to search the list of man pages for possible matches based on a search term. It's crude but sometimes helpful. Here is an example of a search for man pages using the search term partition: apropos partiton The first field in each line of output is the name of the man page, and the second field shows the section. Note that the man command with the "-k" option performs the same function as apropos.

Creating Our Own Commands with alias

It's possible to put more than one command on a line by separating each command with a semicolon. The first thing we have to do is dream up a name for our new command. Let's try "test". Before we do that, it would be a good idea to find out if the name "test" is already being used. To find out, we can use the type command again: type test The name test is already taken. type foo alias foo='cd /usr; ls; cd -' foo type foo unalias foo (remove an alias) type foo type ls alias There is one tiny problem with defining aliases on the command line. They vanish when our shell session ends. In Chapter 11, "The Environment", we will see how to add our own aliases to the files that establish the environment each time we log on.

--help - Display Usage Information

Many executable programs support a "--help" option that displays a description of the command's supported syntax and options. For example: mkdir --help Some programs don't support the "--help" option, but try it anyway. Often it results in an error message that will reveal the same usage information.

README and Other Program Documentation Files

Many software packages installed on our system have documentation files residing in the /usr/share/doc directory. Most of these are stored in plain text format and can be viewed with less. Some of the files are in HTML format and can be viewed with a web browser. We may encounter some files ending with a ".gz" extension. This indicates that they have been compressed with the gzip compression program. The gzip package includes a special version of less called zless that will display the contents of gzipcompressed text files.

ls command common options

Option / Long Option / Description -a /--all /List all files, even those with names that begin with a period, which are normally not listed (that is, hidden). -A /--almost-all /Like the -a option above except it does not list . (current directory) and .. (parent directory). -d /--directory /Ordinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents. -F /--classify /This option will append an indicator character to the end of each listed name. For example, a forward slash (/) if the name is a directory. -h /--human-readable /In long format listings, display file sizes in human readable format rather than in bytes. -l Display results in long format. -r /--reverse /Display the results in reverse order. Normally, ls displays its results in ascending alphabetical order. -S /Sort results by file size. -t /Sort by modification time.

cp Options

Option / Long Option / Meaning -a / --archive / Copy the files and directories and all of their attributes, including ownerships and permissions. Normally, copies take on the default attributes of the user performing the copy. -i / --interactive / Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, cp will silently (meaning there will be no warning) overwrite files. -r / --recursive / Recursively copy directories and their contents. This option (or the -a option) is required when copying directories. -u / --update / When copying files from one directory to another, only copy files that either don't exist or are newer than the existing corresponding files, in the destination directory. This is useful when copying large numbers of files as it skips files that don't need to be copied. -v / --verbose / Display informative messages as the copy is performed.

mv Options

Option / Long Option / Meaning -i / --interactive / Before overwriting an existing file, prompt the user for confirmation. If this option is not specified, mv will silently overwrite files. -u / --update / When moving files from one directory to another, only move files that either don't exist, or are newer than the existing corresponding files in the destination directory. -v / --verbose /Display informative messages as the move is performed.

pwd

Print name of current working directory. When we first log in to our system (or start a terminal emulator session) our current working directory is set to our home directory. Each user account is given its own home directory and it is the only place a regular user is allowed to write files.

Wildcards

Since the shell uses filenames so much, it provides special characters to help us rapidly specify groups of filenames. These special characters are called wildcards. Using wildcards (which is also known as globbing) allows us to select filenames based on patterns of characters. Wildcard / meaning * / Matches any characters ? / Matches any single character [characters] / Matches any character that is a member of the set characters [!characters] / Matches any character that is not a member of the set characters [[:class:]] / Matches any character that is a member of the specified class

Deposing of Unwanted Output

Sometimes "silence is golden," and we don't want output from a command, we just want to throw it away. This applies particularly to error and status messages. The system provides a way to do this by redirecting output to a special file called "/dev/null". This file is a system device often referred to as a bit bucket, which accepts input and does nothing with it. To suppress error messages from a command, we do this: ls -l /bin/usr 2> /dev/null

which - Display an Executable's Location

Sometimes there is more than one version of an executable program installed on a system. While this is not common on desktop systems, it's not unusual on large servers. To determine the exact location of a given executable, the which command is used. which ls which only works for executable programs, not builtins nor aliases that are substitutes for actual executable programs.

Symbolic Links

Symbolic links were created to overcome the limitations of hard links. Symbolic links work by creating a special type of file that contains a text pointer to the referenced file or directory. A file pointed to by a symbolic link, and the symbolic link itself are largely indistinguishable from one another. For example, if we write something to the symbolic link, the referenced file is written to. However when we delete a symbolic link, only the link is deleted, not the file itself. If the file is deleted before the symbolic link, the link will continue to exist but will point to nothing. In this case, the link is said to be broken. In many implementations, the ls command will display broken links in a distinguishing color, such as red, to reveal their presence.

Redirecting Standard Input

The cat command reads one or more files and copies them to standard output like so: cat [file...] We can use it to display files without paging. For example, the following will display the contents of the file ls-output.txt: cat ls-output.txt cat is often used to display short text files. Since cat can accept more than one file as an argument, it can also be used to join files together. we could join them back together with this command as follows: cat movie.mpeg.0* > movie.mpeg Since wildcards always expand in sorted order, the arguments will be arranged in the correct order. If cat is not given any arguments, it reads from standard input and since standard input is, by default, attached to the keyboard, it's waiting for us to type something. cat The quick brown fox jumped over the lazy dog. Next, type a Ctrl-d (i.e., hold down the Ctrl key and press "d") to tell cat that it has reached end of file (EOF) on standard input: In the absence of filename arguments, cat copies standard input to standard output, so we see our line of text repeated. We can use this behavior to create short text files. Let's say we wanted to create a file called lazy_dog.txt containing the text in our example. We would do this: cat > lazy_dog.txt The quick brown fox jumped over the lazy dog. Type the command followed by the text we want to place in the file. Remember to type Ctrl-d at the end. cat lazy_dog.txt Now that we know how cat accepts standard input, in addition to filename arguments, let's try redirecting standard input. cat < lazy_dog.txt The quick brown fox jumped over the lazy dog. Using the < redirection operator, we change the source of standard input from the keyboard to the file lazy_dog.txt.

cp - Copy Files and Directories

The cp command copies files or directories. It can be used two different ways. The following: cp item1 item2 copies the single file or directory item1 to the file or directory item2 and the following: cp item... directory copies multiple items (either files or directories) into a directory.

ln - Create Links

The ln command is used to create either hard or symbolic links. It is used in one of two ways. The following creates a hard link: ln file link The following creates a symbolic link: ln -s item link to create a symbolic link where item is either a file or a directory

mv - Move and Rename Files

The mv command performs both file moving and file renaming, depending on how it is used. In either case, the original filename no longer exists after the operation. mv is used in much the same way as cp, as shown here: mv item1 item2 to move or rename the file or directory item1 to item2 or: mv item... directory to move one or more items from one directory to another.

Shell

The shell is a program that takes keyboard commands and passes them to the operating system to carry out. Almost all Linux distributions supply a shell program from the GNU Project called bash.

type - Display a Command's Type

The type command is a shell builtin that displays the kind of command the shell will execute, given a particular command name. It works like this: type command where "command" is the name of the command we want to examine. Here are some examples: type type type ls type cp

whatis - Display One-line Manual Page Descriptions

The whatis program displays the name and a one-line description of a man page matching a specified keyword: whatis ls

Redirecting Standard Output and Standard Error to One File

There are cases in which we may want to capture all of the output of a command to a single file. To do this, we must redirect both standard output and standard error at the same time. ls -l /bin/usr > ls-output.txt 2>&1 Using this method, we perform two redirections. First we redirect standard output to the file ls-output.txt and then we redirect file descriptor 2 (standard error) to file descriptor 1 (standard output) using the notation 2>&1. Notice that the order of the redirections is significant. The redirection of standard error must always occur after redirecting standard output or it doesn't work. Second method: ls -l /bin/usr &> ls-output.txt In this example, we use the single notation &> to redirect both standard output and standard error to the file ls-output.txt. We can also append the standard output and standard error streams to a single file like so: ls -l /bin/usr &>> ls-output.txt

less /etc/passwd

To examine the file that defines all the system's user accounts. To exit less, press the q key.

Redirecting Standard Error

To redirect standard error we must refer to its file descriptor. While we have referred to the first three of these file streams as standard input, output and error, the shell references them internally as file descriptors 0, 1, and 2, respectively. The shell provides a notation for redirecting files using the file descriptor number. Since standard error is the same as file descriptor number 2, we can redirect standard error with this notation: ls -l /bin/usr 2> ls-error.txt

less

View file contents. The less command is a program to view text files. Throughout our Linux system, there are many files that contain human-readable text. The less program provides a convenient way to examine them. Text is a simple one-to-one mapping of characters to numbers. It is very compact. Fifty characters of text translates to fifty bytes of data. It is important to understand that text only contains a simple mapping of characters to numbers. Why would we want to examine text files? Because many of the files that contain system settings (called configuration files) are stored in this format, and being able to read them gives us insight about how the system works. In addition, some of the actual programs that the system uses (called scripts) are stored in this format. The less command is used like this: less filename To exit less, press the q key.

ls ~ /usr -a

We can even specify multiple directories. In the following example, we list both the user's home directory (symbolized by the "~" character) and the /usr directory.

Relative pathnames

Where an absolute pathname starts from the root directory and leads to its destination, a relative pathname starts from the working directory. To do this, it uses a couple of special notations to represent relative positions in the file system tree. These special notations are "." (dot) and ".." (dot dot). The "." notation refers to the working directory and the ".." notation refers to the working directory's parent directory. Now let's say that we wanted to change the working directory to the parent of /usr/ bin which is /usr. [me@linuxbox bin]$ cd .. [me@linuxbox usr]$ pwd /usr

Commonly Used Character Classes

[:alnum:] Matches any alphanumeric character [:alpha:] Matches any alphabetic character [:digit:] Matches any numeral [:lower:] Matches any lowercase letter [:upper:] Matches any uppercase letter

cp Examples

cp file1 file2 / Copy file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created. cp -i file1 file2 / Same as previous command, except that if file2 exists, the user is prompted before it is overwritten. cp file1 file2 dir1 / Copy file1 and file2 into directory dir1. The directory dir1 must already exist. cp dir1/* dir2 / Using a wildcard, copy all the files in dir1 into dir2. The directory dir2 must already exist. cp -r dir1 dir2 / Copy the contents of directory dir1 to directory dir2. If directory dir2 does not exist, it is created and, after the copy, will contain the same contents as directory dir1. If directory dir2 does exist, then directory dir1 (and its contents) will be copied into dir2.

mv examples

mv file1 file2 - Move file1 to file2. If file2 exists, it is overwritten with the contents of file1. If file2 does not exist, it is created. In either case, file1 ceases to exist. mv -i file1 file2 - Same as the previous command, except that if file2 exists, the user is prompted before it is overwritten. mv file1 file2 dir1 - Move file1 and file2 into directory dir1. The directory dir1 must already exist. mv dir1 dir2 - If directory dir2 does not exist, create directory dir2 and move the contents of directory dir1 into dir2 and delete directory dir1. If directory dir2 does exist, move directory dir1 (and its contents) into directory dir2.


Conjuntos de estudio relacionados

Chapter 22 Savings, Interest, Rates, and the Market for Loanable Funds

View Set

Chapter 9 - Data Privacy and Confidentiality

View Set

12.6.10 Remote Services Practice Questions

View Set

Chapter 6 Consumer Choice Utility Assignment

View Set

Lab Assessment 11: Integumentary System

View Set

Pediatric Nursing Final Exam Study Set

View Set