Skip to main content

Managing Files Using Command-Line Tool – Basic Linux Command

Managing Files Using Command-Line Tool – Basic Linux Command

Managing Files Using Command-Line tools – Basic Linux Commands

Objective



  • Create Files, Directory and Sub-directory.
  • Copy Files, Directory and Sub-directory.
  • Link Files, Directory and Sub-directory.
  • Move Files, Directory and Sub-directory.
  • Remove Files, Directory and Sub-directory.

Managing Files Using Command-Line Tool – Basic Linux Command

File management involve creating, deleting, copying and moving files. Additionally, directories can be created, deleted, copied, and moved to help organize file logically. When working at the command-line, file management requires awareness of the current working directory to choose either absolute or relative path syntax as most efficient for the immediate task.

Create Directory

The mkdir command creates one or more directories and sub-directories. This command will generating error if the file name already exists or when attempting to create a directory in a parent directory that doesn’t exists. The -p (parent) option creates missing parent directory for the destination.
~]$  mkdir Documents/imp
mkdir: cannot create directory ‘Documents/imp’: No such file or directory

The mkdir failed because Documents was misspelled and the directory Documents doesn’t exists. If the user had user mkdir -p, there would be no error.
~]$  mkdir -p Documents/imp
~]$ ls
Desktop  Document  Documents  Downloads  Music  Picture  Public  Templates  Videos 

Copy Files

The cp command copies one or more file to become new, independent files. The Syntax of Copy command allow copying an existing file to a new file in the current or another directory, or copying multiple files into another directory. In any destination, new file name must be unique. If file name is not unique, the copy command will automatically overwrite the existing file. And if you want to copy non-empty directory, with contents, you must be use -r (recursive) option with this copy command.
~]$ cd Document
Document]$ cp imp1.txt  imp3.txt
Document]$ ls
imp imp1.txt imp3.txt
Document]$ 

Move File

The mv command renames file in the same directory, or relocates files to a new directory. Files contents remain unchanged. File moved to a different file system require creating a new file by copying the source file, then deleting the source file. Although normally, transparent to the user, large files may take noticeable longer to move.
~]$ cd Documents
~]$ ls
abhi.txt 
~]$ mv Document/imp1.txt Documents
~]$ cd Documents
~]$ ls
abhi.txt  imp1.txt

Rename files and Directory

The rm command deletes file, but not directories. If you want to delete a directory with contain sub-directory or file, you must use -r (recursive) option. If you want to delete empty directory, so you can use rmdir command to do that.
~]$ rm -r  Documents/abhi.txt
Documents]$ ls
imp1.txt
Document]$ cd ..
~]$ rm -r Documents/imp1.txt
~]$

Comments

Popular posts from this blog

sed

Sed Command in Linux/Unix with examples SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. o     SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution). o     SED command in unix supports regular expression which allows it perform complex pattern matching. Syntax: sed OPTIONS... [SCRIPT] [INPUTFILE...] Example: Consider the below text file as an input. $cat > geekfile.txt unix is great os. unix is opensource. unix is free os. learn operating system. unixlinux which one you choose. unix is easy to learn.unix ...

initramfs" file is deleted or corrupted on your RHEL or CentOS 7

Initrd/Initramfs image provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root filesystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root filesystem which was mounted from initrd/initramfs is then moved to a directory and can be subsequently unmounted. Their are chances that either you might have accidentally deleted "initramfs" file from the /boot partition or it is corrupted due to some reason.  Then boot process will get interrupted and you will see below error: error: file '/initramfs-3.10.0-957.el7.x86_64.img' not found. Good news is you can still recover this "initramfs" by following below steps: Step 1 :  Mount RHEL or CentOS 7 ISO image on your physical server and boot from it. In case you are using HPE Prolient server you can mount this ISO image on iLO, if this is virtual environment then mount it accordingly and reboot...

nw commands

troubleshoot commands in Linux.   1. ifconfig ifconfig (interface configurator) command   is use to initialize an interface, assign IP  Address to interface and enable or disable  interface on demand. With this command  you can view IP Address and Hardware / MAC   address assign to interface and also MTU (Maximum transmission unit) size. # ifconfig   eth0       Link encap:EthernetHWaddr 00:0C:29:28:FD:4C inet addr:192.168.50.2   Bcast:192.168.50.255   Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link           UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1           RX packets:6093 errors:0 dropped:0 overruns:0 frame:0  ...
# # #