{"id":53,"date":"2018-10-10T16:25:00","date_gmt":"2018-10-10T08:25:00","guid":{"rendered":"https:\/\/yeslq.com\/20181053.html"},"modified":"2018-10-10T16:25:00","modified_gmt":"2018-10-10T08:25:00","slug":"the-linux-command-line-manipulating-files","status":"publish","type":"post","link":"https:\/\/yeslq.com\/?p=53","title":{"rendered":"The Linux Command Line&#8212;Manipulating Files"},"content":{"rendered":"<h1 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><i style=\"font-size: x-small;\"><a href=\"http:\/\/linuxcommand.org\/tlcl.php\" style=\"color: #002740;\">The Linux Command Line&nbsp;<\/a><\/i><span style=\"font-size: xx-small;\">by William Shotts<\/span><\/h1>\n<div><span style=\"font-size: xx-small;\"><br \/><\/span><\/div>\n<div><span style=\"font-size: xx-small;\"><\/p>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">This lesson will introduce you to the following commands:<\/div>\n<ul style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">\n<li><tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/cp1.html\" style=\"color: #002740;\">cp<\/a><\/tt>&nbsp;&#8211; copy files and directories<\/li>\n<li><tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/mv1.html\" style=\"color: #002740;\">mv<\/a><\/tt>&nbsp;&#8211; move or rename files and directories<\/li>\n<li><tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/rm1.html\" style=\"color: #002740;\">rm<\/a><\/tt>&nbsp;&#8211; remove files and directories<\/li>\n<li><tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\"><a href=\"http:\/\/linuxcommand.org\/lc3_man_pages\/mkdir1.html\" style=\"color: #002740;\">mkdir<\/a><\/tt>&nbsp;&#8211; create directories<\/li>\n<\/ul>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">These four commands are among the most frequently used Linux commands. They are the basic commands for manipulating both files and directories.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Now, to be frank, some of the tasks performed by these commands are more easily done with a graphical file manager. With a file manager, you can drag and drop a file from one directory to another, cut and paste files, delete files, etc. So why use these old command line programs?<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">The answer is power and flexibility. While it is easy to perform simple file manipulations with a graphical file manager, complicated tasks can be easier with the command line programs. For example, how would you copy all the HTML files from one directory to another, but only copy files that did not exist in the destination directory or were newer than the versions in the destination directory? Pretty hard with with a file manager. Pretty easy with the command line:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp -u *.html destination<\/tt><\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><span style=\"font-size: small;\">Wildcards<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Before I begin with our commands, I want to talk about a shell feature that makes these commands so powerful. Since the shell uses filenames so much, it provides special characters to help you rapidly specify groups of filenames. These special characters are called&nbsp;<i>wildcards<\/i>. Wildcards allow you to select filenames based on patterns of characters. The table below lists the wildcards and what they select:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Summary of wildcards and their meanings\">\n<caption>Summary of wildcards and their meanings<\/caption>\n<tbody>\n<tr>\n<th><strong>Wildcard<\/strong><\/th>\n<th><strong>Meaning<\/strong><\/th>\n<\/tr>\n<tr>\n<td><strong>*<\/strong><\/td>\n<td>Matches any characters<\/td>\n<\/tr>\n<tr>\n<td><strong>?<\/strong><\/td>\n<td>Matches any single character<\/td>\n<\/tr>\n<tr>\n<td><strong>[<i>characters<\/i>]<\/strong><\/td>\n<td>Matches any character that is a member of the set&nbsp;<i>characters<\/i>. The set of characters may also be expressed as a&nbsp;<i>POSIX character class<\/i>such as one of the following:<\/p>\n<table align=\"center\" cellpadding=\"3\" summary=\"POSIX Character Classes\">\n<caption>POSIX Character Classes<\/caption>\n<tbody>\n<tr>\n<td><strong>[:alnum:]<\/strong><\/td>\n<td>Alphanumeric characters<\/td>\n<\/tr>\n<tr>\n<td><strong>[:alpha:]<\/strong><\/td>\n<td>Alphabetic characters<\/td>\n<\/tr>\n<tr>\n<td><strong>[:digit:]<\/strong><\/td>\n<td>Numerals<\/td>\n<\/tr>\n<tr>\n<td><strong>[:upper:]<\/strong><\/td>\n<td>Uppercase alphabetic characters<\/td>\n<\/tr>\n<tr>\n<td><strong>[:lower:]<\/strong><\/td>\n<td>Lowercase alphabetic characters<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>[!<i>characters<\/i>]<\/strong><\/td>\n<td>Matches any character that is not a member of the set&nbsp;<i>characters<\/i><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Using wildcards, it is possible to construct very sophisticated selection criteria for filenames. Here are some examples of patterns and what they match:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Examples of wildcard matching.\">\n<caption>Examples of wildcard matching<\/caption>\n<tbody>\n<tr>\n<th><strong>Pattern<\/strong><\/th>\n<th><strong>Matches<\/strong><\/th>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">*<\/pre>\n<\/td>\n<td>All filenames<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">g*<\/pre>\n<\/td>\n<td>All filenames that begin with the character &#8220;g&#8221;<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">b*.txt<\/pre>\n<\/td>\n<td>All filenames that begin with the character &#8220;b&#8221; and end with the characters &#8220;.txt&#8221;<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">Data???<\/pre>\n<\/td>\n<td>Any filename that begins with the characters &#8220;Data&#8221; followed by exactly 3 more characters<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">[abc]*<\/pre>\n<\/td>\n<td>Any filename that begins with &#8220;a&#8221; or &#8220;b&#8221; or &#8220;c&#8221; followed by any other characters<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">[[:upper:]]*<\/pre>\n<\/td>\n<td>Any filename that begins with an uppercase letter. This is an example of a character class.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">BACKUP.[[:digit:]][[:digit:]]<\/pre>\n<\/td>\n<td>Another example of character classes. This pattern matches any filename that begins with the characters &#8220;BACKUP.&#8221; followed by exactly two numerals.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">*[![:lower:]]<\/pre>\n<\/td>\n<td>Any filename that does not end with a lowercase letter.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">You can use wildcards with any command that accepts filename arguments.<\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><a href=\"https:\/\/draft.blogger.com\/null\" name=\"cp\"><span style=\"font-size: small;\">cp<\/span><\/a><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">The&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp<\/tt>&nbsp;program copies files and directories. In its simplest form, it copies a single file:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp&nbsp;<i>file1 file2<\/i><\/tt><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">It can also be used to copy multiple files (and\/or directories) to a different directory:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp&nbsp;<i>file... directory<\/i><\/tt><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\"><b>A note on notation:<\/b>&nbsp;&#8230; signifies that an item can be repeated one or more times.<\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Other useful examples of&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp<\/tt>&nbsp;and its options include:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Examples of the cp command.\">\n<caption>Examples of the cp command<\/caption>\n<tbody>\n<tr>\n<th><strong>Command<\/strong><\/th>\n<th><strong>Results<\/strong><\/th>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp <i>file1 file2<\/i><\/pre>\n<\/td>\n<td>Copies the contents of&nbsp;<i>file1<\/i>&nbsp;into&nbsp;<i>file2<\/i>. If&nbsp;<i>file2<\/i>&nbsp;does not exist, it is created;&nbsp;<b>otherwise,&nbsp;<i>file2<\/i>&nbsp;is silently overwritten with the contents of&nbsp;<i>file1<\/i>.<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp -i <i>file1 file2<\/i><\/pre>\n<\/td>\n<td>Like above however, since the &#8220;-i&#8221; (interactive) option is specified, if&nbsp;<i>file2<\/i>&nbsp;exists, the user is prompted before it is overwritten with the contents of&nbsp;<i>file1<\/i>.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp <i>file1 dir1<\/i><\/pre>\n<\/td>\n<td>Copy the contents of&nbsp;<i>file1<\/i>&nbsp;(into a file named&nbsp;<i>file1<\/i>) inside of directory&nbsp;<i>dir1<\/i>.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp -R <i>dir1 dir2<\/i><\/pre>\n<\/td>\n<td>Copy the contents of the directory&nbsp;<i>dir1<\/i>. If directory&nbsp;<i>dir2<\/i>&nbsp;does not exist, it is created. Otherwise, it creates a directory named&nbsp;<i>dir1<\/i>within directory&nbsp;<i>dir2<\/i>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><span style=\"font-size: small;\">mv<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">The&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv<\/tt>&nbsp;command moves or renames files and directories depending on how it is used. It will either move one or more files to a different directory, or it will rename a file or directory. To rename a file, it is used like this:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv&nbsp;<i>filename1 filename2<\/i><\/tt><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">To move files (and\/or directories) to a different directory:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv&nbsp;<i>file... directory<\/i><\/tt><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Examples of&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv<\/tt>&nbsp;and its options include:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Examples of the mv command\">\n<caption>Examples of the mv command<\/caption>\n<tbody>\n<tr>\n<th><strong>Command<\/strong><\/th>\n<th><strong>Results<\/strong><\/th>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv <i>file1 file2<\/i><\/pre>\n<\/td>\n<td>If&nbsp;<i>file2<\/i>&nbsp;does not exist, then&nbsp;<i>file1<\/i>&nbsp;is renamed&nbsp;<i>file2<\/i>.&nbsp;<b>If&nbsp;<i>file2<\/i>&nbsp;exists, its contents are silently replaced with the contents of&nbsp;<i>file1<\/i>.<\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv -i <i>file1 file2<\/i><\/pre>\n<\/td>\n<td>Like above however, since the &#8220;-i&#8221; (interactive) option is specified, if&nbsp;<i>file2<\/i>&nbsp;exists, the user is prompted before it is overwritten with the contents of&nbsp;<i>file1<\/i>.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv <i>file1 file2 file3 dir1<\/i><\/pre>\n<\/td>\n<td>The files&nbsp;<i>file1, file2, file3<\/i>&nbsp;are moved to directory&nbsp;<i>dir1<\/i>. If&nbsp;<i>dir1<\/i>&nbsp;does not exist,&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv<\/tt>&nbsp;will exit with an error.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv <i>dir1 dir2<\/i><\/pre>\n<\/td>\n<td>If&nbsp;<i>dir2<\/i>&nbsp;does not exist, then&nbsp;<i>dir1<\/i>&nbsp;is renamed&nbsp;<i>dir2<\/i>. If&nbsp;<i>dir2<\/i>&nbsp;exists, the directory&nbsp;<i>dir1<\/i>&nbsp;is moved within directory&nbsp;<i>dir2<\/i>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><span style=\"font-size: small;\">rm<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">The&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm<\/tt>&nbsp;command removes (deletes) files and directories.<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm&nbsp;<i>file...<\/i><\/tt><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">It can also be used to delete directories:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm -r&nbsp;<i>directory...<\/i><\/tt><\/div>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Examples of&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm<\/tt>&nbsp;and its options include:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Examples of the rm command.\">\n<caption>Examples of the rm command<\/caption>\n<tbody>\n<tr>\n<th><strong>Command<\/strong><\/th>\n<th><strong>Results<\/strong><\/th>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm <i>file1 file2<\/i><\/pre>\n<\/td>\n<td>Delete&nbsp;<i>file1<\/i>&nbsp;and&nbsp;<i>file2<\/i>.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm -i <i>file1 file2<\/i><\/pre>\n<\/td>\n<td>Like above however, since the &#8220;-i&#8221; (interactive) option is specified, the user is prompted before each file is deleted.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm -r <i>dir1 dir2<\/i><\/pre>\n<\/td>\n<td>Directories&nbsp;<i>dir1<\/i>&nbsp;and&nbsp;<i>dir2<\/i>&nbsp;are deleted along with all of their contents.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><br style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\" \/><\/p>\n<div style=\"background-color: white; border: 1px solid black; color: red; font-family: verdana, arial, helvetica, sans-serif; padding: 1em;\">\n<h2 style=\"font-weight: normal;\"><span style=\"font-size: small;\">Be careful with rm!<\/span><\/h2>\n<p>Linux does not have an undelete command. Once you delete something with&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm<\/tt>, it&#8217;s gone. You can inflict terrific damage on your system with&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm<\/tt>&nbsp;if you are not careful, particularly with wildcards.<br \/><b><i>Before you use&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-style: normal;\">rm<\/tt>&nbsp;with wildcards, try this helpful trick:<\/i><\/b>&nbsp;construct your command using&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">ls<\/tt>&nbsp;instead. By doing this, you can see the effect of your wildcards before you delete files. After you have tested your command with&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">ls<\/tt>, recall the command with the up-arrow key and then substitute&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm<\/tt>&nbsp;for&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">ls<\/tt>&nbsp;in the command.<\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><a href=\"https:\/\/draft.blogger.com\/null\" name=\"mkdir\"><span style=\"font-size: small;\">mkdir<\/span><\/a><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">The&nbsp;<tt style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mkdir<\/tt>&nbsp;command is used to create directories. To use it, you simply type:<\/div>\n<div style=\"background-color: black; color: lime; font-family: verdana, arial, helvetica, sans-serif; padding: 0.5em;\"><tt style=\"font-family: courier, lucidatypewriter, monospace;\">[me@linuxbox me]$<\/tt>&nbsp;<tt style=\"background: transparent; color: white; font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mkdir&nbsp;<i>directory...<\/i><\/tt><\/div>\n<h2 style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-weight: normal;\"><span style=\"font-size: small;\">Using Commands With Wildcards<\/span><\/h2>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif;\">Since the commands we have covered here accept multiple file and directories names as arguments, you can use wildcards to specify them. Here are a few examples:<\/div>\n<table border=\"\" cellpadding=\"8\" style=\"background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif;\" summary=\"Using commands with wildcards.\">\n<caption>Command examples using wildcards<\/caption>\n<tbody>\n<tr>\n<th><strong>Command<\/strong><\/th>\n<th><strong>Results<\/strong><\/th>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">cp *.txt text_files<\/pre>\n<\/td>\n<td>Copy all files in the current working directory with names ending with the characters &#8220;.txt&#8221; to an existing directory named&nbsp;<i>text_files<\/i>.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">mv my_dir ..\/*.bak my_new_dir<\/pre>\n<\/td>\n<td>Move the subdirectory&nbsp;<i>my_dir<\/i>&nbsp;and all the files ending in &#8220;.bak&#8221; in the current working directory&#8217;s parent directory to an existing directory named&nbsp;<i>my_new_dir<\/i>.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre style=\"font-family: courier, lucidatypewriter, monospace; font-weight: bold;\">rm *~<\/pre>\n<\/td>\n<td>Delete all files in the current working directory that end with the character &#8220;~&#8221;. Some applications create backup files using this naming scheme. Using this command will clean them out of a directory.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background-color: white; font-family: verdana, arial, helvetica, sans-serif; padding: 1em;\">\n<div style=\"text-align: right;\"><\/div>\n<\/div>\n<p><\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Linux Command Line&nbsp;by William Shotts This less &#8230; <a title=\"The Linux Command Line&#8212;Manipulating Files\" class=\"read-more\" href=\"https:\/\/yeslq.com\/?p=53\" aria-label=\"\u9605\u8bfb The Linux Command Line&#8212;Manipulating Files\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,6],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-linux","category-shell","category-the-linux-command-line"],"_links":{"self":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":0,"href":"https:\/\/yeslq.com\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"wp:attachment":[{"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yeslq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}