Skip to main content
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Articles
lp_course
lp_lesson
Back
HomeFreeSome of the useful Unix Command

Some of the useful Unix Command

Last Updated: August 16, 2025
15 min read
47

 

Unix File Names

It is important to understand the rules for creating Unix files:
  • Unix is case sensitive! For example, “fileName” is different from “filename”.
  • It is recommended that you limit names to the alphabetic characters, numbers, underscore (_), and dot (.). Dots (.) used in Unix filenames are simply characters and not delimiters between filename components; you may include more than one dot in a filename. Including a dot as the first character of a filename makes the file invisible (hidden) to the normal ls command; use the -a flag of the ls command to display hidden files.
  • Although many systems will allow more, a safe length is 14 characters per file name.
Unix shells typically include several important wildcard characters. The asterisk (*) is used to match 0 or more character (e.g., abc* will match any file beginning with the letters abc), the question mark (?) is used to match any single character, and the left ([) and right (]) square brackets are used to enclose a string of characters, any one of which is to match. Execute the following commands and observe the results:
  ls m*
  ls *.f
  ls *.?
  ls [a-d]*
Notes for PC users: Unix uses forward slashes ( / ) instead of backslashes ( ) for directories

Looking at the Contents of Files

You can examine the contents of files using a variety of commands. catmorepghead, and tail are described here. Of course, you can always use an editor; to use vi in “read-only” mode to examine the contents of the file “argtest”, enter:
  vi  -R   argtest
You can now use the standard vi commands to move through the file; however, you will not be able to make any changes to the contents of the file. This option is useful when you simply want to look at a file and want to guarantee that you make no changes while doing so.
Use the vi “”” command to exit from the file.

cat Command

cat is a utility used to conCATenate files. Thus it can be used to join files together, but it is perhaps more commonly used to display the contents of a file on the screen.
Observe the output produced by each of the following commands:
  cd;    cd  xmp
  cat        cars
  cat  -vet  cars
  cat  -n    cars
The semicolon (;) in the first line of this example is a command separator which enables entry of more than one command on a line. When the <Return> key is pressed following this line, the command cd is issued which changes to your home directory. Then the command “cd xmp” is issued to change into the subdirectory “xmp.” Entering this line is equivalent to having entered these commands sequentially on separate lines. These two commands are included in the example to guarantee that you are in the subdirectory containing “cars” and the other example files. You need not enter these commands if you are already in the “xmp” directory created when you copied the example files (see Sample Files if you have not already copied these files).
The “-vet” options enable display of tab, end-of-line, and other non-printable characters within a file; the “-n” option numbers each line as it is displayed.
You can also use the cat command to join files together:
  cat  page1
  cat  page2
  cat  page1  page2 > document
  cat  document
Note: If the file “document” had previously existed, it will be replaced by the contents of files “page1” and “page2”.

Cautions in using the cat command

The cat command should only be used with “text” files; it should not be used to display the contents of binary (e.g., compiled C or FORTRAN programs). Unpredictable results may occur, including the termination of your logon session, when the cat command is used on binary files. Use the command “file *” to display the characteristics of files within a directory prior to using the cat command with any unknown file. You can use the od (enter “man od” for details on use of Octal Dump) command to display the contents of non-text files. For example, to display the contents of “a.out” in both hexadecimal and character representation, enter:
  od  -xc  a.out
Warning! cat (and other Unix commands) can destroy files if not used correctly. For example, as illustrated in the Sobell book, the cat (also cp and mv) command can overwrite and thus destroy files. Observe the results of the following command:
  cat  letter page1 >  letter

Typically Unix does not return a message when a command executes successfully. Here the Unix operating system will attempt to complete the requested command by first initializing the file “letter” and then writing the current contents of “letter” (now nothing) and “page1” into this file. Since “letter” has been reinitialized and is also named as a source file, an error diagnostic is generated. Part of the Unix philosophy is “No news is good news”. Thus the appearance of a message is a warning that the command was not completed successfully.

Now use the “cat” command to individually examine the contents of the files “letter” and “page1”. Observe that the file “letter” does not contain the original contents of the files “letter” and “page1” as was intended.
Use the following command to restore the original file “letter”:
  cp  ~aixstu00/xmp/letter  .

more Command

You may type or browse files using the more command. The “more” command is useful when examining a large file as it displays the file contents one page at a time, allowing each page to be examined at will. As with the man command, you must press the space bar to proceed to the next screen of the file. On many systems, pressing the <b> key will enable you to page backwards in the file. To terminate more at any time, press <q>.
To examine a file with the more command, simply enter:
  more  file_name

See the online manual pages for additional information.

The man command uses the more command to display the manual pages; thus the commands you are familiar with in using man will also work with more.
Not all Unix systems include the more command; some implement the pg command instead. VTAIX includes both the more and pg commands. When using the pgcommand, press <Return> to page down through a file instead of using the space bar.
Observe the results of entering the following commands:
  more  argtest
  pg    argtest

head Command

The head command is used to display the first few lines of a file. This command can be useful when you wish to look for specific information which would be found at the beginning of a file. For example, enter:
  head  argtest

tail Command

The tail command is used to display the last lines of a file. This command can be useful to monitor the status of a program which appends output to the end of a file. For example, enter:
  tail  argtest

Copying, Erasing, Renaming

Warning! The typical Unix operating system provides no ‘unerase’ or ‘undelete’ command. If you mistakenly delete a file you are dependent upon the backups you or the system administrator has maintained in order to recover the file. You need to be careful when using commands like copy and move which may result in overwriting existing files. If you are using the C or Korn Shell, you can create a command alias which will prompt you for verification before overwriting files with these commands.

Copying Files

The cp command is used to copy a file or group of files. You have already seen an example application of the cp command when you copied the sample files to your userid (see Sample Files). Now let’s make a copy of one of these files. Recall that you can obtain a listing of the files in the current directory using the lscommand. Observe the results of the following commands:

Continue Reading This Article

Sign in with a free account to unlock the full article and access the complete MapYourTech knowledge base.

764+ Technical Articles
47+ Professional Courses
20+ Engineering Tools
47K+ Professionals
100% Free Access
No Credit Card Required
Instant Full Access
Sanjay Yadav

Optical Networking Engineer & Architect • Founder, MapYourTech

Optical networking engineer with nearly two decades of experience across DWDM, OTN, coherent optics, submarine systems, and cloud infrastructure. Founder of MapYourTech.

Follow on LinkedIn
Share:

Leave A Reply

You May Also Like

51 min read 1 0 Like Single-Carrier and Multi-Carrier Coherent Optics: Architecture, Performance, and the Path to 1.6T and Beyond...
  • Free
  • April 14, 2026
22 min read 1 0 Like Submarine vs Terrestrial Optical Systems: Engineering Differences Skip to main content Submarine vs Terrestrial...
  • Free
  • April 14, 2026
7 min read 5 0 Like Modelling, Simulation and Use Cases for Digital Twin in Optical Networks Modelling, Simulation and...
  • Free
  • April 13, 2026
Love Reading on Your Phone?
MapYourTech Pro is now on the App Store

Everything you enjoy here — now fits right in your pocket. Whether you're on the commute, waiting at the lab, or unwinding on the couch — keep learning on the go.

690+ Articles 100+ Simulators Pro-Grade Tools Visual Infographics 50+ Courses Interview Guides

Course Title

Course description and key highlights

Course Content

Course Details