Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6
Experiment 1: Date:
Aim: Practice on basic Linux commands.
Basic Linux Commands pwd: pwd (print working directory) – The pwd command is used to display the name of the current working directory in the Linux system using the terminal. Syntax: pwd [-LP] Sr.No. Option & Description
1 -L (logical)Display the value of $pwd if it names the current working directory
2 -P (physical)Display the physical directory, without any soft link
3 --helpDisplays a help message and then exits.
Output: [cloudera@localhost ~]$ pwd /home/cloudera Create File using touch: touch command: It is used to create a file without any content. The file created using touch command is empty. This command can be used when the user doesn’t have data to store at the time of file creation. Syntax: touch file_name output: touch sample To Add Content Existing File using vi: The vi editor tool is an interactive tool as it displays changes made in the file on the screen while you edit the file. In vi editor you can insert, edit or remove a word as cursor moves throughout the file. Commands are specified for each function like to delete it's x or dd. The vi editor is case-sensitive. For example, p allows you to paste after the current line while P allows you to paste before the current line. vi syntax vi <fileName> Command mode This is what you'll see when you'll press enter after the above command. If you'll start typing, nothing will appear as you are in command mode. By default vi opens in command mode. Insert mode: To move to the insert mode press i. Although, there are other commands also to move to insert mode which we'll study in next page. I Look at the above snapshot, after pressing i we have entered into insert mode. Now we can write anything. To move to the next line press enter. Once you have done with your typing, press esc key to return to the command mode. To save and quit You can save and quit vi editor from command mode. Before writing save or quit command you have to press colon (:). Colon allows you to give instructions to vi. exit vi table:
Commands Action
:wq Save and quit
:w Save
:q Quit
:w fname Save as fname
ZZ Save and quit
:q! Quit discarding changes made
:w! Save (and write to non-writable file)
Type :wq to save and exit the file.
Look at the above snapshot, command :wq will save and quit the vi editor. When you'll type it in command mode, it will automatically come at bottom left corner. Output: [cloudera@localhost ~]$ vi sample566 To see Content of file using cat command: Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives its content as output. It helps us to create, view, and concatenate files. So let us see some frequently used cat commands. Syntax cat file_name output: [cloudera@localhost ~]$ cat sample566 Good Morning Welcome to BDA Lab To see List of file using ls command: In Linux, the command "ls" is one of the most commonly used. It's used to display a list of files and sub-directories in the current directory. If you're new to using the command line, the first command you should learn is probably ls.This command can be used by both regular users as well as system administrators. syntax: ls [ Options ] [File] Options Description ls –a list all files including hidden file starting with '.'. ls –d list directories - with ' */'. ls –l list with long format - show permissions. ls –F Append indicator (one of */=>@|) to entries. ls –lh This command will show you the file sizes in human readable format. ls –r list in reverse order.ls -ilist file's inode(index) number. ls –ltr View Reverse Output Order by Date. ls –t sort by time & date .ls –n It is used to print group ID and owner ID instead of their names. ls –m A list of entries separated by commas should fill the width. ls –g This allows you to exclude the owner and group information columns. [cloudera@localhost ~]$ ls Files in the cloudera: datasets Documents eclipse Music Public Templates worksp Desktop Downloads lib Pictures sample566 Videos Create Directory: mkdir command in Linux allows the user to create directories (also referred to as folders in some operating systems). This command can create multiple directories at once as well as set the permissions for the directories. It is important to note that the user executing this command must have enough permission to create a directory in the parent directory, or he/she may receive a ‘permission denied’ error. Syntax: mkdir directory-name [cloudera@localhost ~]$ mkdir 21-566 Change Directory: cd command in Linux known as the change directory command. It is used to move efficiently from the current working directory to different directories in our System. Syntax: cd directory-name output: [cloudera@localhost ~]$ cd 21-566 [cloudera@localhost 21-566]$ ls Copy file: cp stands for a copy. This command is used to copy files or groups of files or directories. It creates an exact image of a file on a disk with a different file name. cp command requires at least two filenames in its arguments. Syntax: cp [OPTION] Source Destination cp [OPTION] Source Directory cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory Output: [cloudera@localhost 21-566]$ cd .. [cloudera@localhost ~]$ cp sample502 21-566 [cloudera@localhost 21-566]$ ls sample566 Move file In UNIX-based operating systems like Linux and macOS, `mv` stands for “move”. But in this article, we will be talking about the “mv command in Linux”. As its name suggests this command is used to rename file directories and move files from one location to another within a file system. Two Distinct Functions of `mv` Command 1) Renaming a file or directory. 2) Moving a file or directory to another location Syntax: mv [options(s)] [source_file_name(s)] [Destination_file_name] output: [cloudera@localhost ~]$ mv sample502 21-566 [cloudera@localhost ~]$ ls [cloudera@localhost ~]$ ls List of files in local host: 21-566 Documents lib Public workspace datasets Downloads Music Templates Desktop eclipse Pictures Videos Remove file: rm stands for remove here. rm command is used to remove objects such as files, directories, symbolic links and so on from the file system like UNIX. Syntax: rm [OPTION]... FILE.. [cloudera@localhost 21-566]$ rm sample566 rm: remove regular file `sample566'? y [cloudera@localhost 21-566]$ ls [cloudera@localhost ~]$ rmdir 21-566 [cloudera@localhost ~]$ ls datasets Documents eclipse Music Public Videos Desktop Downloads lib Pictures Templates workspace Clear the Screen: clear is a standard Unix computer operating system command that is used to clear the terminal screen. Syntax Clear Output: [cloudera@localhost ~]$ clear System Info-commands Date date command is used to display the system date and time. date command is also used to set date and time of the system. Syntax: date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] Output: [cloudera@localhost ~]$ date Wed Jul 31 22:55:52 PDT 2024 Cal: cal command is a calendar command in Linux which is used to see the calendar of a specific month or a whole year. Syntax: cal [ [ month ] year] Output: [cloudera@localhost ~]$ cal July 2024 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 W command The ‘w’ command in Linux gives us important information about who is currently using the computer, how much the computer is being used, and what programs are running. It’s a handy tool for people who take care of computer systems, as it helps them keep an eye on what users are doing, Syntax of `w` command in Linux w [options] user [...] Output: [cloudera@localhost ~]$ w 67 column window is too narrow Whoami whoami command is used both in Unix Operating System and as well as in Windows Operating System. It is basically the concatenation of the strings “who”,”am”,”i” as whoami. It displays the username of the current user when this command is invoked. It is similar as running the id command with the options -un. The earliest versions were created in 2.9 BSD as a convenience form for who am i, the Berkeley Unix who command’s way of printing just the logged in user’s identity. The GNU version was written by Richard Mlynarik and is part of the GNU Core Utilities (coreutils). Output: [cloudera@localhost ~]$ who am i cloudera pts/0