I have completed steps to use Amazon Elastic Compute Cloud (Amazon EC2) to quickly create and connect to an instance of Ubunutu Linux, and I have access to the Linux command shell. How can I find information about the core utilities to configure and manage files?

Linux includes more than 100 "core" utilities for file management, system administration, security, and storage, among other things. The core utilities included with Linux distributions are the result of the free software GNU Operating System initiative started in 1983 by Richard Stallman. Because GNU software is designed to work with Unix systems, it is available with most Linux distributions.

This article provides a summary of the GNU file utilities that are available for Ubuntu 14.04 and later. The names of the core utilities described here are linked to an online man (manual) page at http://www.gnu.org.

Note: To get more information about the GNU file utilities available on your Amazon EC2 Linux instance, use one of the following commands:

     <cmd> --help – displays arguments for the utility

     info <cmd> – displays general information about the utility

     man <cmd> – displays the manual page for the utility

The following list provides a synopsis of the GNU file utilities available with Ubuntu Linux:

chcon – Changes the SELinux security context of the specified files. Requires that SELinux is enabled, as determined by the sestatus command.

Note: For more information about Security Enhanced Linux (SELinux), see http://wiki.centos.org/HowTos/SELinux.

$ chcon -h system_u:object_r:httpd_sys_content_t /var/www

chgrp – Changes group ownership of the specified files to the specified group.

$ cd #switch to home directory

$ > chgrptest #create empty file chgrptest

$ ls –g | grep test$ #display information about chgrptest

-rw-rw-r-- 1 admn 0 Feb 16 12:00 chgrptest

$ sudo chgrp users chgrptest #change group ownership to users

$ ls –g | grep test$ #display information about chgrptest

-rw-rw-r-- 1 users 0 Feb 16 12:10 chgrptest

$ rm chgrptest #clean up

chown – Changes user and/or group ownership of the specified files to the specified user and/or group.

$ cd #switch to home directory

$ > chowntest #create empty file chowntest

$ ls –l | grep test$ #display information about chowntest

-rw-rw-r-- 1 admn admn 0 Feb 16 12:00 chowntest

$ sudo chown root:users chowntest #change user/group ownership

$ ls –l | grep test$ #display information about chowntest

-rw-rw-r-- 1 root users 0 Feb 16 12:10 chowntest

$ rm chowntest #clean up

chmod – Changes permissions of the specified files or directories where permissions are set for user(u), group(g), other(o), or all(a) as read(r), write(w), or execute(x).

$ cd #switch to home directory

$ > chmodtest #create empty file chmodtest

$ ls –l | grep test$ #display information about chmodtest

-rw-rw-r-- 1 admn admn 0 Feb 16 12:00 chmodtest

$ chmod u+x,g+x,o+x chmodtest #user, group, other granted execute

# chmod a+x chmodtest will also accomplish same as above

$ ls –l | grep test$ #display information about chmodtest

-rwxrwxr-x 1 admn admn 0 Feb 16 12:10 chmodtest

$ chmod u-x,g-x,o-x chmodtest #revert permissions

# chmod a-x chmodtest will also accomplish same as above

$ ls –l | grep test$ #display information about chmodtest

-rw-rw-r-- 1 admn admn 0 Feb 16 12:15 chmodtest

$ rm chmodtest #clean up

cp – Copies files or directories.

$ cd #switch to home directory

$ > cptest #create empty file cptest

$ ls –l | grep test$ #display information about cptest

-rw-rw-r-- 1 admn admn 0 Feb 16 12:00 cptest

$ cp cptest cp2test

$ ls –l | grep test$ #display information about cptest, cp2test

-rw-rw-r-- 1 admn admn 0 Feb 16 12:10 cp2test

-rw-rw-r-- 1 admn admn 0 Feb 16 12:00 cptest

$ rm cptest cp2test #clean up

dd – Bitstream duplicates a file while optionally performing conversions on the file. Ensure that the arguments input file (if=) and output file (of=) are entered in the correct order; if they are reversed, dd has earned the nickname 'data destroyer'.

$ cd #switch to home directory

$ echo 'DDTEST' > ddtest #create file ddtest

$ less ddtest #display contents of ddtest, q to exit

DDTEST #contents all uppercase

$ dd if=ddtest of=ddtest conv=lcase #convert to lowercase

0+0 records in

0+0 records out

0 bytes (0 B) copied, 0.0018935 s, 0.0 kB/s

$ less ddtest #display contents of ddtest, q to exit

ddtest #dd converted contents of file to lowercase

$ rm ddtest #clean up

df – Reports how much disk space is used and available on all mounted file systems.

$ df -h

Filesystem                       Size Used Avail Use% Mounted on

/dev/mapper/trusty-vg-root       15G  1.6G   13G  11% /

none                             4.0K    0  4.0K   0% /sys/fs/cg

udev                             2.0G 4.0K  2.0G   1% /dev

tmpfs                            395M 260K  394M   1% /run

.................................................................

dir – Lists directory contents in columns, sorted vertically with any special characters represented by backslash escape sequences.

$ cd / #switch to top level directory

$ dir

bin  boot dev  etc  home initrd.img lib lib64 media mnt opt

proc root run  sbin srv  sys        tmp usr   var   vm

dircolors – Configures colors displayed for ls or dir. dircolors is typically implemented using an alias specified in a configuration file such as .bashrc or .bash_profile and can read a file describing directory colors to diplay with ls or dir. If no file is specified, a precompiled database (/usr/bin/dircolors) is used. For information about the colors designated in the precompiled database, run dircolors -p (print database). To list the colors currently used by ls when invoked with ls --color, run dircolors with no arguments. Run echo "$LS_COLORS" to display the LS_COLORS environment variable.

$ dircolors #prints colors used by ls when invoked with --color

$ dircolors –p #print contents of precompiled colors database

install – Copies files while setting file mode bits and, if possible, file owner and group.

$ cd #switch to home directory

$ > installtest #create empty file installtest

$ ls –l | grep test$ #display information about installtest

-rw-rw-r-- 1 admn admn 0 Feb 16 12:00 installtest

$ sudo install –o root –g users installtest install2test

# copy & change owner to root, group to users, modify permissions

$ ls –l | grep test$ #display info about test files

-rwxr-xr-x 1 root users 0 Feb 16 12:10 install2test

-rw-rw-r-- 1 admn admn  0 Feb 16 12:00 installtest

rm installtest install2test #cleanup, press y when prompted

ln – Creates links between files. Creates hard links by default; creates symbolic links with the -s switch.

$ cd #switch to home directory

$ sudo ln –s /bin/ping /usr/bin/ping #create symbolic link

$ env – PATH="/usr/bin" #change path to exclude /bin/ping

PATH=/usr/bin

$ ping localhost #verify that ping works from symbolic link

PING localhost (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.041

...

ls – Lists information about files and directories.

$ cd # switch to home directory

$ ls -A

.bash_history .bash_logout .bash_profile .bashrc .profile .ssh

mkdir – Creates a new directory.

$ cd #switch to home directory

$ mkdir –v documents #-v for verbose

mkdir: created directory 'documents'

$ rm –v –r documents #clean up

removed directory: 'documents'

mkfifo – Creates named pipes (FIFOs) with the specified name. Pipes allow separate processes to communicate even if the processes have not been designed explicitly to work together.

$ cd #switch to home directory

$ screen #open separate terminal session, press spacebar

$ mkfifo newpipe #create named pipe

$ ls –alt > newpipe & #send ls –alt to newpipe in background

[1] PID

$ exit #exit separate terminal session

exit

...

[screen is terminating]

$ less < newpipe #print piped output from previous session

-rw------- 1 admn admn 12734 Feb 16 12:00 .bash_history

drwxr-xr-x 5 admn admn  4096 Feb 16 12:00 .

prw-rw-r-- 1 admn admn     0 Feb 16 12:00 newpipe

#note left-most entry in line above indicates p for pipe

...

#press q to exit

$ rm newpipe #clean up

mknod – Creates a character device, block device, or named pipe with the specified name. mknod was originally used to create character and block devices to populate /dev/, equivalent functionality is now automatically performed with software such as udev.

$ cd #switch to home directory

$ screen #open separate terminal session, press spacebar

$ mknod pipe2 p #create named pipe

$ ls –alt > pipe2 & #send ls –alt to pipe2 in background

$ [1] PID

$ exit #exit separate terminal session

exit

...

[screen is terminating]

$ less < pipe2 #print piped output from previous session

-rw------- 1 admn admn 12734 Feb 16 12:00 .bash_history

drwxr-xr-x 5 admn admn  4096 Feb 16 12:00 .

prw-rw-r-- 1 admn admn0 Feb 16 12:00 pipe2

#note left-most entry in line above indicates p for pipe

...

#press q to exit

$ rm pipe2 #clean up

mktemp – Creates temporary files and directories. Specify a template ending with at least three consecutive 'x' characters (XXX), which will be replaced by random alphanumeric characters.

$ cd #switch to home directory

$ mktemp tempfile.XXX

tempfile.EQ1

$ rm tempfile.EQ1 #clean up

mv – Moves or renames files or directories.

$ cd #switch to home directory

$ mkdir olddirectory #create /olddirectory

$ mv –v olddirectory newdirectory #move /olddirectory

'olddirectory' -> 'newdirectory'

$ rm –v –r newdirectory #clean up

removed directory: 'newdirectory'

realpath – Resolves any symbolic links and references to '/./','/../', and additional '/' characters.

$ cd #switch to home directory

$ realpath –-relative-to=/usr /tmp /usr/bin

../tmp

bin

rm – Removes files and directories, including directories containing files or subdirectories when using the appropriate command option.

$ cd #switch to home directory

$ mkdir spreadsheets #create spreadsheets directory

$ cd spreadsheets #switch to spreadsheets directory

$ $ > emptyfile #create emptyfile under /spreadsheets

$ cd #switch to home directory

$ rm –v –r spreadsheets #remove /spreadsheets and file(s)

removed 'spreadsheets/emptyfile'

removed directory: 'spreadsheets'

rmdir – Removes empty directories.

$ cd #switch to home directory

$ mkdir emptydir

$ rmdir –v emptydir

rmdir: removing directory, 'emptydir'

shred – Overwrites files to inhibit unauthorized recovery of the files.

$ cd #switch to home directory

$ cp .profile .profilebak #copy .profile to .profilebak

$ shred -v .profilebak

shred: .profilebak: pass 1/3 (random)...

shred: .profilebak: pass 2/3 (random)...

shred: .profilebak: pass 3/3 (random)...

$ rm .profilebak #clean up

sync – Writes data that is buffered in memory to disk.

$ sync

touch – Changes the timestamp of the specified files.

$ cd #switch to home directory

$ ls –al | grep .p | grep –v b #display info about .profile

-rw-r--r-- 1 admn  admn   675 Feb 16 12:00 .profile

$ touch .profile

$ ls –al | grep .p | grep –v b #display info about .profile

-rw-r--r-- 1 admn  admn  675 Feb 16 12:15 .profile

truncate – Shrinks or extends files to the specified size.

$ truncate –s 4096 .profile

$ ls –al | grep .p | grep –v b #display info about .profile

-rw-r--r-- 1 admn  admn  4096 Feb 16 12:30 .profile

vdir – Prints a verbose directory contents list.

cd /home #switch to home directory

home$ vdir

drwxr-xr-x 2 greg  greg  4096 Feb 16 12:01 greg

drwxr-xr-x 2 john  john  4096 Feb 16 12:01 john

drwxr-xr-x 5 admn  admn  4096 Feb 16 12:00 admn

Linux, core utilities, GNU, coreutils, shell


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.