User Tools

Site Tools


ops102:file_globbing_common_commands_and_text_editors

This is an old revision of the document!


File Globbing, Common Commands, and Text Editors

Filename Patterns

Linux and Windows systems both allow ambiguous filenames, which use wildcard symbols to enable filename matching. The process of converting an ambiguous filename, or filename pattern, into a list of matching filenames is called globbing or filename expansion.

On a Linux system, globbing is performed by the shell. This means that all arguments are subject to globbing, whether they're intended to be a filename argument or not.

On a Windows system, ambiguous filenames are converted into a list of filenames by the command or application. This means that arguments that are not filenames are not subject to filename expansion. However, it also means that applications must contain additional code to perform globbing.

Wildcard Symbols

SymbolMeaning in LinuxMeaning in Windows
*Matches zero or more charactersMatches zero or more characters
?Matches one characterMatches one character, unless at the end of the filename or immediately before the dot preceeding the extension in which case it matches zero or one character
[[list]]Matches any one of the characters within the brackets (note that it matches exactly one of the characters)Not applicable

Examples

PatternMatches on LinuxDoes not match on LinuxMatches on WindowsDoes not match on Windows
a*a aa aaa alpha argonautAlpha bananaa aa aaa alpha Alphabanana
b*eblue bitered green blotblue bitered green blot
c[[oa]]tcat cotcoat cat cot coat (Not applicable)
d?edue doeduo Doe datedue doe Doeduo date
a??aaa abcaa abcdaaa abc aaabcd

Therefore the command

  del *.pdf

on Windows, or

  rm *.pdf

on Linux will remove all files with the extension .pdf

Common Basic Commands

Here are some basic commands useful for managing the filesystem and performing basic tasks:

Linux Windows Description
lsdirDisplays the contents of a directory – by default, the current directory, or the directories specified as arguments (or a specific file, if specified).
echoechoPlaces a message on the screen (the message is given as positional arguments)
cal Displays a simple calendar
datedate /t<br />time /tDisplays the date/time
whoquserDisplays information about the logged in user(s)
whoamiwhoamiDisplays the name of the current user
clearclsClears the terminal display. Note: in the Bash shell, you can also clear the screen during command entry by typing Ctrl+L
treetreeDisplays the filesystem hierarchy starting at the current directory (or the given directory, if an argument is provided).
mkdirmkdirCreates a directory/folder
rmdirrmdirRemoves a directory/folder
rmdelRemoves/deletes one or more files. Specify -rf to recursively force delete a directory and its contents on Linux, or /s to recursively delete a directory and its contents on Windows.
cdcdChanges to the given directory, if one is given. If no directory is given, displays the current directory (Windows) or changes to your home directory (Linux). On Windows, a drive designator may be provided, in which case the current directory will be set on the indicated drive.
X:(Where X is a drive designator) Switches to the selected drive.
pwd Prints the current working directory.
cpcopyCopy one or more files to a new name/location.
mvmoveMoves a file from one directory to another.
mvren<br>renameRenames a file (on Linux, the filename and location are considered to be the same thing)
cattypeDumps the contents of a text file on the terminal (if there is a lot of text, the display will scroll; if the file is a non-text file, the results are undefined!)
more<br>lessmoreDisplays a file one screen at a time. (Linux: the less command is a more powerful version of the more command, which allows things like scrolling backwards)
cut Selects specific columns from a text file
sortsortSorts a text file
diffcomp<br/>fcShows the differences between (text) files
uniq Displays identical consequtive lines only once
tr Translates/replaces/deletes occurrences of characters
grepfindSearches files for text
find Searches for files
touchcopy NUL: filenameCreates an empty file (Linux: if the file exists, touch will just update the date/time of modification).

Viewing Online Documentation

To find a Linux command to perform a particular function, use the apropos or man -k commands to search the online documentation. For example, to see commands related to “calendar”:

apropos calendar
man -k calendar # same as the above!

To view information about a Linux command, use the online manual (“manpages”), accessed with the man command:

man commandname

For example, to view the online manual page for cp, enter the command:

man cp

On Windows, you can see a list of commonly used commands by typing

help

To view information about a Windows command, use the online help:

help commandname

For example, to view the online help for dir, enter the command:

help dir

Alternately, to get a brief help summary for a command, enter the name of the command followed by /? – for example, to get a help summary for the copy command, type

copy /?

Text Editors

It's often necessary to edit a text file containing a script, program, data, or configuration information. There are many text editors available.

On Linux systems, most distributions (the organizations or companies responsible for maintaining and distributing the system) have standardized on the nano editor as the default CLI/TUI text editor (replacing the less-user-friendly vi editor). To start nano, type nano and optionally provide a filename:

nano
nano file

Nano provides a help display at the bottom of the screen. The carat ^ symbol indicates the control key, so the help text “^X Exit” means that you would press Ctrl-X to exit from the editor.

The current versions of Windows (Windows 10 & 11) do not provide a CLI/TUI text editor. However, you can run the GUI Notepad editor from the command line (as long as you are not accessing the Windows system remotely through a non-graphical connection):

notepad
notepad file

ops102/file_globbing_common_commands_and_text_editors.1705469951.txt.gz · Last modified: 2024/04/16 18:10 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki