Wednesday, July 19, 2017

C-LAB PROGRAMMING FOR CSE & EEE EXERCISE - 1

EXERCISE - 1
AIM: Understanding LINUX commands.
1. man Command:
The best source of information for most commands can be found in the online manual
pages, known as “man pages” for short. To read a command's man page, type “man
command”.
Syntax: man <command>
Example: man ls
Get help on the “ls” command.

2. Using a Command's Built-In Help:
Many commands have simple “help” screens that can be invoked with special
command flags. These flags usually look like “-h” or “--help”.
Example: ls --help

3. cat Command:
“cat” is short for concatenate. This command is used to create, view and concatenate
files.
Syntax: cat [argument] [specific file]
Example1: cat > filename
This command is used to creating a file with the given filename.
Example2: cat filename
This command is used to view the contents of given filename.
Example3: cat file1 file2 > file3
This command combines the contents of the file1 and file2 into file3.

4. pwd Command:
"pwd" stands for present working directory. It displays your current position in the
UNIX file system.
Syntax: pwd
Example: pwd
There are no options (or arguments) with the "pwd" command. It is simply used to
report your current working directory.

5. ls Command:
"ls" stands for list. It is used to list information about files and directories.
Syntax: ls [options] [names]
Examples: ls
This is the basic "ls" command, with no options. It provides a very basic
listing of the files in your current working directory. Filenames beginning with a
decimal are considered hidden files, and they are not shown.
ls -a
The -a option tells the ls command to report information about all files,
including hidden files.
ls -l
C Programming
2
The -l option tells the "ls" command to provide a long listing of information
about the files and directories it reports. The long listing will provide important
information about file permissions, user and group ownership, file size, and creation
date.

6. mkdir Command:
mkdir stands for make directory. This command is used to create a directory.
Syntax: mkdir directory_name
Example: mkdir mydirectory

7. cd Command:
cd stands for Change Directory.
Syntax: cd
When typed it returns you to your home directory.
Syntax: cd directory
Change into the specified directory name.

8. cp Command:
Copies a file from one location to another.
Syntax: cp file_name directory
Example: cp myfile.txt /mydir
Copies the myfile.txt file to the /mydir directory

9. mv Command:
Moves a file to a new location, or renames it.
Syntax: mv file_name directory
Example: mv myfile1.txt /mydir
Copy the file to /mydir, and delete it from the original location.
Syntax: mv old_filename new_filename
Example: mv myfile1.txt myfile2.txt
Rename myfile1.txt to myfile2.txt.

10. rm Command:
This command is used to delete a file.
Syntax: rm filename
Example: rm myfile.txt
Removes myfile.txt file.

11. rmdir Command:
This command is used to remove an empty directory.
Syntax: rmdir dir_name
Example: rmdir mydir

Removes mydir directory if the directory is empty only.