How to manipulate files by command prompt ?
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY fazeela.ma
3 years ago
Linux-Terminal
0
comments comment

We are no strangers to commands in bash. Bash provides an ample amout of commands to manipulate on files. The main commands that are commonly used are,

  • cp - copy files and directories
  • mv - move or rename files and directories
  • rm - remove files and directories
  • mkdir - create directories

cp is a command used to copy the file in a particular destination to another. Eg.,

cp README.txt /home/zyx/Projects/zyx 

Here, we are trying to copy the file README.txt in the current directory to the folder zyx in the path /home/zyx/Projects/.

mv is a command used to move the file in a particular destination to another. Eg.,

mv README.txt /home/zyx/Projects/zyx 

Here, we are trying to move the file README.txt in the current directory to the folder zyx in the path /home/zyx/Projects/.

rm is a command used to remove the file in a particular destination. Eg.,

rm README.txt 

Here, we are trying to remove the file README.txt in the current directory.

The command mkdir is used to create a folder. Eg.,

mkdir new 

Here we trying to create a new folder in the current directory.

There is so many extensions are used along with these commands, which let us use it in interrative and in a recursive manner.


RELATED ARTICLE

close

on 27th April 2012 / by webmaster
A web developer’s life becomes much saner if he/she has easy access to all page header information. Firefox offers you PLUGIN-NAME that helps you inspect headers. Here is something for the terminally inclined ones among you - wget. To view the http headers give the following command in gnome terminal : wget -S --spider www.example.com where,example.com is your domain,--spider tells wget to act like spider and to just check the pages without actually downloading them,-S gives the Server response. Typical output of the wget command, when used as mentioned above, is as follows: HTTP request sent, awaiting response... HTTP/1.1 200 OK Date: Mon, 12 Mar 2012 07:58:38 GMT Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.9 Last-Modified: Mon, 12 Mar 2012 07:16:27 GMT ETag: "d47b-854608c0" Accept-Ranges: bytes Content-Length: 54395 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Expires: Sun, 19 Nov 1978 05:00:00 GMT X-Header: Boost Citrus 1.8 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html; charset=utf-8 Length: 54395 (53K) [text/html] Remote file exists and could contain further links, but recursion is disabled -- not retrieving. Web Development Debugging Linux Terminal Leave a reply Your email address will not be published. Required fields are marker *
close

on 12th October 2012 / by sandeep.sasikumar
The command "setfacl" refers to Set File Access Control Lists and "getfacl" refers to Get File Access Control List. Each file and directory in a Linux filesystem is created with a specific set of file permissions for its access. Each user can have different set of file access permissions. The permissions can be set using the setfacl utility. In order to know the access permissions of a file or directory we use getfacl. The getfacl command displays the access permissions of files and directories with file name, owner, group and the ACL's(Access Control List). When we create a directory it is created with a default set of access permissions and by using getfacl we will be able to see the access rights. What are the default access permissions for a newly created directory? To know this, first open a terminal and open the folder in which you want to create a subfolder. Next type "mkdir <folder-name>" and press the ENTER key. This will create a folder with default access permissions. To know the access permissions, type getfacl <folder-name> Now you will see the output of getfacl as something like the following: # file: file-name # owner: # group: user::rwx user:x:--- user:y:r-- group::r-- mask::rw- other::---Thus from the output of getfacl we will be able to see the access permissions of a file. In the above example, when we type getfacl <file-name> the output will be shown as in the above format. It displays the owner of the file, the group which has access to it and also its various users and their access rights. In the above case the users are x and y, where the user 'x' is having no permission on this file and therefore it is shown with --- symbol indicating no read/write/execute permissions for the user x. Now considering the other user 'y’, it is having the permission r-- which means read-only rights. The default umask is set to rw- (read/write permissions). How to copy the ACL of one folder to other? Consider an example of copying the ACL of the directory named "x" to "y". For this, firstly we should know the ACL of the directory named "x". To obtain this type the command getfacl x This will display the ACL of the directory named "x" in the above mentioned format: # file: x # owner: # group: user::rwx user:x:--- user:y:r-- group::r-- mask::rw- other::---To copy the ACL of one directory to the other we use the setfacl command. That is setfacl --setfile =- y As mentioned we want to copy the ACL of "x" to "y", for this we have to type the command getfacl x | setfacl -R –setfile = -y Here "getfacl x" will get the ACL of the directory named "x" and this output is given to the setfacl command using pipe. Thus getfacl will give the ACL of the directory "x" and setfacl -R –setfile = -y will set that ACL to the directory named "y". "-R" is used to set this ACL recursively. How to inherit the ACL of parent directory to its child? To copy the ACL of the parent directory to its child, use the following command getfacl . | setfacl -R --setfile = -subdirectory_name The "getfacl ." will get the ACL of the parent directory and setfacl will set that ACL to its sub-directories. Now for verification, type: getfacl subdirectory_name and also getfacl directory_name If both are same then the ACL of the sub-directory is same as the ACL of the parent. Linux System Administration Linux Shell Linux Terminal Security Leave a reply Your email address will not be published. Required fields are marker * ts (not verified) access_time 26 May 2019 - 22:45 The above command: getfacl x | setfacl -R –setfile = -y must reaad like this to work: getfacl x | setfacl -R –setfile=- y TS (not verified) access_time 26 May 2019 - 22:45 Forget about my previous post. This is the correct syntax now getfacl x | setfacl -R –set-file=- y anju rohilla (not verified) access_time 26 May 2019 - 22:45 when we run the command like this # setfacl -m u:anju:rw- /html where anju is a user and html is a file in /. then it changes the acess of the for group not for the user,why? Add new comment
more_horiz
close

on 01st June 2013 / by deepa.n
Backup! Backup! Backup! Always back up your Drupal site's code and database before you actually start making any changes to your site. Do you have access to the control panel? Cool! Go ahead and create a zip file of your entire site, export your db, download it to your local machine and you are done. Read on to know how to backup your Drupal site. Open up a terminal window in your Linux box and type the following commands to get it done instantly. At first create a backup directory to store the site's backup in the root folder. $ sudo mkdir backupHow to create a Mysql dump? $ mysqldump -u [username] -p[password] [dbname] > db.backup_20121004.sqlOR $ mysqldump -u [username] -p [dbname] db.backup_20121004.sqlHere is an example of how you actually use this command and your database back up will be created at the same path.E.g. mysqldump -u root -p example_db > db.backup_20121004.sql How to create a back up of Files and folders? Step 1: Compress files $ tar -zcvpf files.backup_20121004.tar.gz /backupIf the directories require root permission then try the tar command using the sudo command as follows: $ sudo tar -zcvpf files.backup_20121004.tar.gz /backupStep 2: Securely copy the back up files to your machine $ scp [filename] [username]@[host_name]:[destination_folder]OR $ scp [remote_username]@[remote_hostname]:/[path_to_remote]/[filename] [path_to_local]/[filename]For more details try this command: $ man scp in the terminal. Hope the article was helpful, please leave your feedback using the comments box below. Ubuntu Drupal Linux Tips Linux Terminal Leave a reply Your email address will not be published. Required fields are marker *
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.