{"id":137937,"date":"2021-12-03T15:17:34","date_gmt":"2021-12-03T20:17:34","guid":{"rendered":"http:\/\/www.bu.edu\/tech\/?page_id=137937"},"modified":"2025-04-24T12:04:13","modified_gmt":"2025-04-24T16:04:13","slug":"navigation","status":"publish","type":"page","link":"https:\/\/www.bu.edu\/tech\/support\/research\/system-usage\/using-file-system\/navigation\/","title":{"rendered":"File System Commands"},"content":{"rendered":"<h2>Working with Files\/Directories<\/h2>\n<p>Below are some simple examples of basic Linux commands for accessing and changing your files and directories. For all of these commands, you can run <code><span class=\"command\">man<\/span> <span class=\"placeholder\">command_name<\/span><\/code> to see the <a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/man\/1\/\">manual page (system documentation)<\/a> on the command, including an explanation of the available command line options.<\/p>\n<ul>\n<li>Show the current &#8220;full path&#8221;, the directory you are working in with its parent and all levels of grandparents up to the root directory (<b>\/<\/b>):\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">pwd<\/span>\r\n<span class=\"output\">\/usr2\/collab\/adftest2<\/span><\/code><\/pre>\n<\/li>\n<li>Create a file:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">touch<\/span><span class=\"placeholder\"> myfile<\/span><\/code><\/pre>\n<div class=\"highlight-yellow\">This command will create a blank file named <code><span class=\"placeholder\">myfile<\/span><\/code>. You will also want to be able to use a text editor to create or modify an existing text file. A simple graphical editor to use is <code><span class=\"command\">gedit<\/span><\/code>, but more complex editors like <code><span class=\"command\">emacs<\/span><\/code> and <code><span class=\"command\">vi<\/span><\/code> are also available by default.<\/div>\n<\/li>\n<li>Create a directory:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">mkdir<\/span><span class=\"placeholder\"> newdir<\/span><\/code><\/pre>\n<\/li>\n<li>List items, including files and directories, in a directory:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span> <span class=\"placeholder\">newdir<\/span>\r\n<span class=\"output\">newdir<\/span>\r\n<\/code><\/pre>\n<p>There are many options to the <code><span class=\"command\">ls<\/span><\/code> command such as <code><span class=\"command\">ls -l<\/span><\/code> to list the files in a directory in &#8220;long&#8221; (verbose) format such as:<\/p>\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls -l<\/span> <span class=\"placeholder\">newdir<\/span>\r\n<span class=\"output\">total 0\r\ndrwxr-xr-x 3 adftest2 adftest 512 Oct 28 16:03 newdir<\/span>\r\n<\/code><\/pre>\n<p>The letters on the left (&#8220;drwxr-xr-x&#8221;) indicate the &#8220;permissions&#8221; of this file\/directory. The &#8220;d&#8221; indicates that it is a directory. The next 9 characters indicate that it is &#8220;readable&#8221;, &#8220;writable&#8221;, and &#8220;executable&#8221; by you and &#8220;readable&#8221; and &#8220;executable&#8221; by both the members of your project group and the world. The commands you can use to change these &#8220;permissions&#8221; are <b><a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/system-usage\/using-file-system\/file-permissions\/chmod\/\">chmod<\/a><\/b> and <b><a href=\"https:\/\/www.bu.edu\/tech\/support\/research\/system-usage\/using-file-system\/file-permissions\/umask\/\">umask<\/a><\/b>.<\/li>\n<li>Move and\/or rename a file:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">mv<\/span> <span class=\"placeholder\">myfile newdir\/newfilename<\/span>\r\n<\/code><\/pre>\n<p>This command will move the file <code><span class=\"placeholder\">myfile<\/span><\/code> into the directory <code><span class=\"placeholder\">newdir<\/span><\/code> and simultaneously rename it to\u00a0<code><span class=\"placeholder\">newfilename<\/span><\/code>.<\/li>\n<li>Move to a different directory:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">cd<\/span> <span class=\"placeholder\">newdir<\/span>\r\n<\/code><\/pre>\n<p>Move to the newly created <code><span class=\"placeholder\">newdir<\/span><\/code> directory. You can also specify a &#8220;full path&#8221; (a path that starts with a <b>\/<\/b>) such as <code><span class=\"command\">cd \/usr\/local\/bin<\/span><\/code>. Typing just <code><span class=\"command\">cd<\/span><\/code> (or <code><span class=\"command\">cd .<\/span><\/code>) by itself will always take you to your home directory.<\/li>\n<li>Move to the parent (next higher level) directory of the one you are in:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">cd<\/span> ..\r\n<\/code><\/pre>\n<p>This takes you up one level in the SCC directory structure.<\/li>\n<li>Copy a file:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">cp<\/span> <span class=\"placeholder\">newfilename filecopy<\/span>\r\n<\/code><\/pre>\n<p>This command will make a copy of <code><span class=\"placeholder\">newfilename<\/span><\/code> and name it\u00a0<code><span class=\"placeholder\">filecopy<\/span><\/code>. You can copy entire directories by using the <code><span class=\"command\">-r<\/span><\/code> (recursive) option.<\/li>\n<li>Delete a file:\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">rm<\/span> <span class=\"placeholder\">filecopy<\/span>\r\n<span class=\"output\">rm: remove regular empty file `filecopy'?<\/span> <span class=\"command\">y<\/span>\r\n<\/code><\/pre>\n<p>By default you will be asked to confirm that you want to remove a file by typing <b>y<\/b>. You could avoid this by using the command line option <code><span class=\"command\">-f<\/span><\/code> but then you must be much more careful. Empty directories are removed using the command <code><span class=\"command\">rmdir<\/span> <span class=\"placeholder\">directory_name<\/span><\/code>. Full directories can be removed by again using the <code><span class=\"command\">-r<\/span><\/code> (recursive) option to <code><span class=\"command\">rm<\/span><\/code>.<\/li>\n<\/ul>\n<p><a href=\"#top\">Back to Top<\/a><\/p>\n<h2>Tar and Compressed Files<a name=\"COMPRESSION\" href=\"#COMPRESSION\" style=\"text-decoration:none;\">&#x1F517;<\/a><\/h2>\n<p>There are four main archiving (combining multiple files into one <i>archive<\/i> file) and compression (reducing the size of a file) tools on Linux systems with associated tools to reverse the process. It is common to both archive a set of files and then compress the archive, such as a file named <code><span class=\"placeholder\">myarchive.tar.gz<\/span><\/code><\/p>\n<table>\n<tbody>\n<tr>\n<th>Archive\/ Compression Tool<\/th>\n<th>Unarchive \/Uncompression Tool<\/th>\n<th>Archived\/ Compressed Filename Extension<\/th>\n<th>Purpose<\/th>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/gzip\/1\/\">gzip<\/a><\/td>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/gzip\/1\/\">gunzip<\/a><\/td>\n<td>.gz<\/td>\n<td>Compress a large single file<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/compress\/1\/\">compress<\/a><\/td>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/compress\/1\/\">uncompress<\/a><\/td>\n<td>.Z<\/td>\n<td>Compress a large single file<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/zip\/1\/\">zip<\/a><\/td>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/zip\/1\/\">unzip<\/a><\/td>\n<td>.zip<\/td>\n<td>Creating a single compressed file from a group of files<\/td>\n<\/tr>\n<tr>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/tar\/1\/\">tar -c<\/a><\/td>\n<td><a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/tar\/1\/\">tar -x<\/a><\/td>\n<td>.tar<\/td>\n<td>Creating a single file from a group of files<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Usage of the first two tools (<code><span class=\"command\">gzip<\/span><\/code> and <code><span class=\"command\">compress<\/span><\/code>) and their counterparts is straightforward:<\/p>\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span>\r\n<span class=\"output\">myfile<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">compress<\/span> <span class=\"placeholder\">myfile<\/span> <span class=\"comment\"># or replace with gzip<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span>\r\n<span class=\"output\">myfile.Z<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">uncompress<\/span> <span class=\"placeholder\">myfile.Z<\/span> <span class=\"comment\"># or replace with gunzip of a .gz file<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span>\r\n<span class=\"output\">myfile<\/span><\/code><\/pre>\n<p>On Linux systems, <code><span class=\"command\">tar<\/span><\/code> is used much more commonly for archiving sets of files than <code><span class=\"command\">zip<\/span><\/code>. However, you may very well come across ZIP archives, often generated on Windows, which you will need to <code><span class=\"command\">unzip<\/span><\/code>:<\/p>\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">unzip<\/span> <span class=\"placeholder\">example.zip<\/span>\r\n<span class=\"output\">Archive:  example.zip\r\n   creating: Packet1\/\r\n   creating: Packet2\/<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span>\r\n<span class=\"output\">Packet1\/     Packet2\/     example.zip<\/span><\/code><\/pre>\n<p><b>Using Tar<\/b><br \/>\n<a href=\"http:\/\/scv.bu.edu\/cgi-bin\/perl\/manscript\/SGI\/tar\/1\/\">Tar<\/a> has many options. Shown below is an example of generating and then expanding a simple archive. Note that if you have a <b>compressed<\/b> tar file such as <code><span class=\"placeholder\">myarchive.tar.gz<\/span><\/code> you will generally first want to <b>uncompress<\/b> it using the <a href=\"#COMPRESSION\">appropriate tool above<\/a> and then untar it.<\/p>\n<pre class=\"code-block\"><code><span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span> <span class=\"placeholder\">mydir<\/span>\r\n<span class=\"output\">file1  file2<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">tar -cvf<\/span> <span class=\"placeholder\">mydir.tar mydir\/<\/span> <span class=\"comment\"># Generate the archive mydir.tar from the directory mydir and all of its contents.<\/span>\r\n<span class=\"output\">mydir\/\r\nmydir\/file1\r\nmydir\/file2<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">rm -r<\/span> <span class=\"placeholder\">mydir<\/span> <span class=\"comment\"># Remove the original directory for now<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">ls<\/span>\r\n<span class=\"output\">mydir.tar<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">tar -tvf<\/span> <span class=\"placeholder\">mydir.tar<\/span> <span class=\"comment\"># Look at what is in the archive file.<\/span>\r\n<span class=\"output\">drwx------ aarondf\/scv       0 2014-04-30 13:26 mydir\/\r\n-rw------- aarondf\/scv       8 2014-04-30 13:25 mydir\/file1\r\n-rw------- aarondf\/scv      10 2014-04-30 13:26 mydir\/file2<\/span>\r\n<span class=\"prompt\">scc1$<\/span> <span class=\"command\">tar -xvf<\/span> <span class=\"placeholder\">mydir.tar<\/span> <span class=\"comment\"># Expand the archive file in my current directory.<\/span>\r\n<span class=\"output\">mydir\/\r\nmydir\/file1\r\nmydir\/file2<\/span>\r\n<span class=\"prompt\">scc14<\/span> <span class=\"command\">ls *<\/span>\r\n<span class=\"output\">mydir:\r\nfile1  file2\r\n\r\nmydir.tar<\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Working with Files\/Directories Below are some simple examples of basic Linux commands for accessing and changing your files and directories. For all of these commands, you can run man command_name to see the manual page (system documentation) on the command, including an explanation of the available command line options. Show the current &#8220;full path&#8221;, the&#8230;<\/p>\n","protected":false},"author":1692,"featured_media":0,"parent":137933,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/137937"}],"collection":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/users\/1692"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/comments?post=137937"}],"version-history":[{"count":12,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/137937\/revisions"}],"predecessor-version":[{"id":156998,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/137937\/revisions\/156998"}],"up":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/137933"}],"wp:attachment":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/media?parent=137937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}