1. To go a Directory: cd /etc (to root directory cd / ) cd / cd means Change Directory. In this case, you’ve asked to change to the root directory.
2. To see the file List: after going a directory ls (cd /etc then ls) .
The ls: ls stands for “list”, as in “list files”. When you type ls, the system displays a list of all the files in your current working directory.
3. Creating a folder/ directory: mkdir practice. In your home directory, make a directory called practice. cd /, mkdir test (create a test directory in root)
4. Creating a user and give a directory access: First become root user then normally type ‘adduser jsmith' but If you want to give the user ‘John Smith’ a login account you could run ‘useradd jsmith‘ to create a login for him. Once this is done there are two more things you need to do – set the password for this account (they can change it themselves later) – you can do this by running ‘passwd jsmith‘. When you run passwd it will ask you for the password to set twice, to make sure you’ve typed what you think you’ve typed. The next thing you need to do is make a home directory for them. This will normally just involve running:
mkdir /home/jsmith chown jsmith:users /home/jsmith
This creates a directory with the same name as the login account beneath the /home directory – then changes it to be owned by the user. If you omit the ‘chown‘ command the user will not have permission to save files inside their own home directory!
5. Removing user accounts: User accounts can be removed using the
6. Changing user passwords: The system administrator may change any user’s password by typing
7. Copy: cp /etc/profile (cp source destination cp /etc/profile /nazim). cp is short for “copy.” /etc/profile is just a random file on your system, We’ve copied it to . So we’ve created a copy of /etc/profile, and put it in our practice directory.
8. more profile: View the contents of the file profile. more is used to view the contents of text files. It’s called more because it shows a screenfull of the file at a time, and you press the space bar to see more. more will exit when you get to the end of the file, or when you type q (quit).
9. Move: mv profile mysubdirectory. mv stands for “move”. We’ve moved the file profile from the current directory into the subdirectory we created earlier.
10. Delete File: rm myprofile. rm means “remove” — this deletes myprofile. Be careful! Deleting a file on a GNU/Linux system is permanent — there is no undelete. If you rm it, it’s gone, forever.
11. Remove Directory: rmdir mysubdirectory. rmdir is just like rm, only it’s for directories. Notice that rmdir only works on empty directories — if the directory contains files, you must delete those files first, or alternatively use rm -r in place of rmdir.
12. File Manager Commands:
This category make a listing of commands who serve for the file management (make a file, display a file, make a directory,…).
For each command you can find a short description and a link to its manpage (you can also access the manpage by the command man name_of_command in your terminal). See also Documentation on Debian.
Organizing files and directories
cp : Copy one or more files to another location
dir : Briefly list directory contents
file : Tells what kind of files are those listed on command line
gzip/gunzip: Compress or decompress named file(s)
ls : List information about file(s)
mv : Move or rename files or directories
mkdir : Make directory
popd : Remove the top entry from the directory stack, and cd to the new top directory.
pushd : Save and then change the current directory. With no arguments, pushd exchanges the top two directories.
pwd : Display the working directory (Print Working Directory)
rcp : Remote Copy – move files between machines.
rm : Remove files
rmdir : Remove directory
rsh : Remote shell
rsync : Remote file copy – Synchronize file trees across local disks, directories or across a network.
scp : Secure copy (remote file copy program)
sync : Synchronize data on disk with memory
tar : Tape ARchiver, store, list or extract files in an archive.
cat : Display the contents of a file (concatenate)
less : Display output one screen at a time, Search through output, Edit the command line.
more : Display output one screen at a time, less provides more emulation and extensive enhancements.
chgrp : Change group ownership
chmod : Change access permissions, change mode
chown : Change owner, change the user and/or group ownership of each given File to a new Owner.
Obtaining system information
df : Disk Free – display free disk space
du : Disk Usage – report the amount of disk space used by the specified files and for each subdirectory
file : Determine file type
free : Display the usage of RAM
uname : Display the system version
Information on identity of user
groups : Print group names a user is in
id : Print real and effective user id (uid) and group id (gid), prints identity information about the given user, or if no user is specified the current process
whoami : Print the current user id and name (`id -un’)
Finding a file
find : Search a folder hierarchy for filename(s) that meet a desired criteria: Name, Size, File Type,…
locate : Find files
lpc : line printer control program
lpr : off line print – sends a print job to the default system queue
lprint : Print files
lprintd : Abort a printing task
lprintq : List of printing task
lprm : Remove a task in list of printing task
pr : Format text file to printing
history : History of commands
screen : Multiplex a physical terminal between several processes (typically interactive shells)
Basic Linux Commands
mkdir – make directories
mkdir [OPTION] DIRECTORY
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, mode=MODE set permission mode (as in chmod), not rwxrwxrwx – umask
-p, parents no error if existing, make parent directories as needed
-v, verbose print a message for each created directory
-help display this help and exit
-version output version information and exit
cd – change directories
Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.
mv- change the name of a directory
Type mv followed by the current name of a directory and the new name of the directory.
Ex: mv testdir newnamedir
pwd – print working directory
will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page
rmdir – Remove an existing directory
Removes directories and files within the directories recursively.
chown – change file owner and group
chown [OPTION] OWNER[:[GROUP]] FILE
chown [OPTION] :GROUP FILE
chown [OPTION] –reference=RFILE FILE
Change the owner and/or group of each FILE to OWNER and/or GROUP. With –reference, change the owner and group of each FILE to those of RFILE.
-c, changes like verbose but report only when a change is made
-dereference affect the referent of each symbolic link, rather than the symbolic link itself
-h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the ownership of a symlink)
change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute.
-no-preserve-root do not treat `/’ specially (the default)
-preserve-root fail to operate recursively on `/’
-f, -silent, -quiet suppress most error messages
-reference=RFILE use RFILE’s owner and group rather than the specifying OWNER:GROUP values
-R, -recursive operate on files and directories recursively
-v, -verbose output a diagnostic for every file processed
The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect.
-H if a command line argument is a symbolic link to a directory, traverse it
-L traverse every symbolic link to a directory encountered
-P do not traverse any symbolic links (default)
chmod – change file access permissions
chmod [-r] permissions filenames
r Change the permission on files that are in the subdirectories of the directory that you are currently in. permission Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha numeric format.filenames File or directory that you are associating the rights with Permissions
u – User who owns the file.
g – Group that owns the file.
o – Other.
a – All.
r – Read the file.
w – Write or edit the file.
x – Execute or run the file as a program.
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
ls – Short listing of directory contents
-a list hidden files
-d list the name of the current directory
-F show directories with a trailing ‘/’
executable files with a trailing ‘*’
-g show group ownership of file in long listing
-i print the inode number of each file
-l long listing giving details about files and directories
-R list all subdirectories encountered
-t sort by time modified instead of name
cp – Copy files
cp myfile yourfile
Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.
cp -i /data/myfile
Copy the file “/data/myfile” to the current working directory and name it “myfile”. Prompt before overwriting the file.
cp -dpr srcdir destdir
Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir
ln – Creates a symbolic link to a file.
ln -s test symlink
Creates a symbolic link named symlink that points to the file test Typing “ls -i test symlink” will show the two files are different with different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.
locate – A fast database driven file locator.
This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically on most systems.locate whereis Lists all files whose names contain the string “whereis”. directory.
more – Allows file contents or piped output to be sent to the screen one page at a time
less – Opposite of the more command
cat – Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.
whereis – Report all known instances of a command
wc – Print byte, word, and line counts
bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.
cal month year– Prints a calendar for the specified month of the specified year.
cat files– Prints the contents of the specified files.
clear – Clears the terminal screen.
cmp file1 file2 – Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.
diff file1 file2– Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.
dmesg – Prints the messages resulting from the most recent system boot.
fg jobs – Brings the current job (or the specified jobs) to the foreground.
file files – Determines and prints a description of the type of each specified file.
find path -name pattern -print
Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.
finger users – Prints descriptions of the specified users.
free – Displays the amount of used and free system memory.
Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.
head files – Prints the first several lines of each specified file.
ispell files – Checks the spelling of the contents of the specified files.
kill – signal process_ids
Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.
killall – signal program
Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.
mail – Launches a simple mail client that permits sending and receiving email messages.
man section title – Prints the specified man page.
ping host– Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.
reboot– Reboots the system (requires root privileges).
shutdown -r minutes
Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.
sleep time – Causes the command interpreter to pause for the specified number of seconds.
sort files – Sorts the specified files. The command has many useful arguments; see the online documentation.
split file – Splits a file into several smaller files. The command has many arguments; see the online documentation
sync – Completes all pending input/output operations (requires root privileges).
telnet host– Opens a login session on the specified host.
top – Prints a display of system processes that’s continually updated until the user presses the q key.
traceroute host– Uses echo requests to determine and print a network path to the host.
uptime – Prints the system uptime.
w – Prints the current system users.
wall – Prints a message to each user except those who’ve disabled message reception. Type Ctrl-D to end the message.
mkdir command Syntax
The mkdir command has the following syntax:
mkdir dirname1 dirname2
mkdir [option] dieNameHere
mkdir -p dir1/dir2/dir3
Open a terminal and use the mkdir command to create empty directories. The following command would create a directory called foo:
$ mkdir foo
To list directories, enter:
$ ls -l
The following command would create two directories within the current directory:
$ mkdir tom jerry
$ ls -l
The -p option allows you to create parent directories as needed (if parent do not already exits). For example, you can create the following directory structure:
$ mkdir -p ~/public_html/images/trip