{"id":943,"date":"2014-02-09T14:15:14","date_gmt":"2014-02-09T13:15:14","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=943"},"modified":"2016-10-11T11:07:17","modified_gmt":"2016-10-11T09:07:17","slug":"mount-fs-survival-guide","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=943","title":{"rendered":"File System Survival Guide"},"content":{"rendered":"<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#Partition\"><span class=\"toc_number toc_depth_1\">1<\/span> Partition<\/a><ul><li><a href=\"#Manage_partition\"><span class=\"toc_number toc_depth_2\">1.1<\/span> Manage partition<\/a><\/li><li><a href=\"#Extend_partition\"><span class=\"toc_number toc_depth_2\">1.2<\/span> Extend partition<\/a><\/li><\/ul><\/li><li><a href=\"#Mount_FileSystem\"><span class=\"toc_number toc_depth_1\">2<\/span> Mount FileSystem<\/a><ul><li><a href=\"#Mount_local_disk\"><span class=\"toc_number toc_depth_2\">2.1<\/span> Mount local disk<\/a><\/li><li><a href=\"#Mount_windows_shared_directory\"><span class=\"toc_number toc_depth_2\">2.2<\/span> Mount windows shared directory<\/a><ul><li><a href=\"#using_smbfs\"><span class=\"toc_number toc_depth_3\">2.2.1<\/span> using smbfs<\/a><\/li><li><a href=\"#using_cifs\"><span class=\"toc_number toc_depth_3\">2.2.2<\/span> using cifs<\/a><\/li><\/ul><\/li><li><a href=\"#Mount_ssh_directory\"><span class=\"toc_number toc_depth_2\">2.3<\/span> Mount ssh directory<\/a><ul><li><a href=\"#Troubleshooting\"><span class=\"toc_number toc_depth_3\">2.3.1<\/span> Troubleshooting<\/a><ul><li><a href=\"#fuse_bad_mount_point_mntmountpoint8217_Transport_endpoint_is_not_connected\"><span class=\"toc_number toc_depth_4\">2.3.1.1<\/span> fuse: bad mount point `\/mnt\/mountpoint&#8217;: Transport endpoint is not connected<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#Mount_nfs\"><span class=\"toc_number toc_depth_2\">2.4<\/span> Mount nfs<\/a><\/li><li><a href=\"#Mount_ftp\"><span class=\"toc_number toc_depth_2\">2.5<\/span> Mount ftp<\/a><\/li><li><a href=\"#Mount_cdrom\"><span class=\"toc_number toc_depth_2\">2.6<\/span> Mount cdrom<\/a><\/li><\/ul><\/li><li><a href=\"#Commands\"><span class=\"toc_number toc_depth_1\">3<\/span> Commands<\/a><ul><li><a href=\"#Find_a_file_containing_a_string\"><span class=\"toc_number toc_depth_2\">3.1<\/span> Find a file containing a string<\/a><\/li><li><a href=\"#Remove_all_tmp_files\"><span class=\"toc_number toc_depth_2\">3.2<\/span> Remove all *.tmp files<\/a><\/li><li><a href=\"#Get_the_top_10_disk_use\"><span class=\"toc_number toc_depth_2\">3.3<\/span> Get the top 10 disk use<\/a><\/li><li><a href=\"#Only_list_folders\"><span class=\"toc_number toc_depth_2\">3.4<\/span> Only list folders<\/a><\/li><li><a href=\"#Retrieve_bash_script_execution_directory_to_use_under_your_bash_script\"><span class=\"toc_number toc_depth_2\">3.5<\/span> Retrieve bash script execution directory (to use under your bash script)<\/a><\/li><li><a href=\"#Get_the_most_recent_element_in_the_current_directory\"><span class=\"toc_number toc_depth_2\">3.6<\/span> Get the most recent element in the current directory<\/a><\/li><li><a href=\"#Copy_files_by_extension_recursively\"><span class=\"toc_number toc_depth_2\">3.7<\/span> Copy files by extension recursively<\/a><\/li><li><a href=\"#Remove_files_older_than_5_days\"><span class=\"toc_number toc_depth_2\">3.8<\/span> Remove files older than 5 days<\/a><\/li><li><a href=\"#find_all_files_that_does_not_have_777_permissions\"><span class=\"toc_number toc_depth_2\">3.9<\/span> find all files that does not have 777 permissions<\/a><\/li><\/ul><\/li><\/ul><\/div>\n<h1><span id=\"Partition\">Partition<\/span><\/h1>\n<h2><span id=\"Manage_partition\">Manage partition<\/span><\/h2>\n<pre lang=\"bash\">\r\n# to create a partition for the disk \/dev\/sda:\r\ncfdisk \/dev\/sda\r\n# to format your partition \/dev\/sda1 in ext4\r\nmkfs.ext4 -j \/dev\/sda1\r\n<\/pre>\n<h2><span id=\"Extend_partition\">Extend partition<\/span><\/h2>\n<pre lang=\"bash\">\r\n# Add 100G to \/dev\/sda1:\r\nlvextend -L +100G \/dev\/sda1\r\n<\/pre>\n<h1><span id=\"Mount_FileSystem\">Mount FileSystem<\/span><\/h1>\n<h2><span id=\"Mount_local_disk\">Mount local disk<\/span><\/h2>\n<p>In your \/etc\/fstab, add this lines:<\/p>\n<pre lang=\"bash\">\r\n\/dev\/sda1 \/mnt\/my-local-disk                     ext4    defaults        1 1\r\n<\/pre>\n<h2><span id=\"Mount_windows_shared_directory\">Mount windows shared directory<\/span><\/h2>\n<h3><span id=\"using_smbfs\">using smbfs<\/span><\/h3>\n<pre lang=\"bash\"> \r\n#install Samba File System:\r\nyum -y install smbfs smbclient\r\n# create directory to mount the shared directory:\r\nmkdir \/mnt\/windows\r\n# mount :\r\nmount -t smbfs \/\/my\/windows\/shared\/directory \/mnt\/windows -o username=username,password=password\r\n<\/pre>\n<h3><span id=\"using_cifs\">using cifs<\/span><\/h3>\n<pre lang=\"bash\">\r\n#install Samba File System:\r\nyum -y install cifs-utils\r\n# create directory to mount the shared directory:\r\nmkdir \/mnt\/windows\r\n# mount :\r\nmount -t cifs \/\/my\/windows\/shared\/directory \/mnt\/windows -o username=username,password=password,defaults,auto,rw,users,exec\r\n# add this line to \/etc\/fstab\r\n# \/\/my\/windows\/shared\/directory         \/mnt\/windows      cifs username=username,password=password,defaults,auto,rw,users,exec            0 0\r\n<\/pre>\n<h2><span id=\"Mount_ssh_directory\">Mount ssh directory<\/span><\/h2>\n<pre lang=\"bash\">\r\n#install Samba File System:\r\nyum -y install sshfs\r\n# create directory to mount the shared directory:\r\nmkdir \/mnt\/ssh\r\n# mount :\r\nmount -t sshfs root@myserver:\/var\/www \/mnt\/ssh<\/pre>\n<p>* Mount ext4 (add this line to \/etc\/fstab):<\/p>\n<pre lang=\"bash\">sshfs#root@myserver:\/var\/www       \/mnt\/ssh      fuse   defaults 0 0\r\n<\/pre>\n<h3><span id=\"Troubleshooting\">Troubleshooting<\/span><\/h3>\n<h4><span id=\"fuse_bad_mount_point_mntmountpoint8217_Transport_endpoint_is_not_connected\">fuse: bad mount point `\/mnt\/mountpoint&#8217;: Transport endpoint is not connected<\/span><\/h4>\n<pre lang=\"bash\">\r\numount -l \/mnt\/mountpoint\r\nmount \/mnt\/mountpoint\r\n<\/pre>\n<h2><span id=\"Mount_nfs\">Mount nfs<\/span><\/h2>\n<pre lang=\"bash\">\r\necho \"install nfs\"\r\nyum -y install nfs-utils nfs-utils-lib\r\necho \"start nfs on startup\"\r\nchkconfig rpcbind on\r\nchkconfig nfs on\r\necho \"start service\"\r\nservice rpcbind start\r\nservice nfs start\r\n# add this line to \/etc\/fstab\r\n# myserver:\/remote\/export  \/local\/directory   nfs      rw,sync,hard,intr  0     0\r\n<\/pre>\n<h2><span id=\"Mount_ftp\">Mount ftp<\/span><\/h2>\n<pre lang=\"bash\">\r\necho \"install curlftpfs\"\r\nyum -y install curlftpfs\r\n# mount:\r\ncurlftpfs ftp:\/\/ftpuser:ftppassword@myftpserver \/mnt\/ftp\r\n<\/pre>\n<h2><span id=\"Mount_cdrom\">Mount cdrom<\/span><\/h2>\n<pre lang=\"bash\">\r\nmkdir \/mnt\/cdrom\r\nmount \/dev\/cdrom \/mnt\/cdrom\r\n<\/pre>\n<h1><span id=\"Commands\">Commands<\/span><\/h1>\n<h2><span id=\"Find_a_file_containing_a_string\">Find a file containing a string<\/span><\/h2>\n<pre lang=\"bash\"> \r\nfind \/my\/path -name \"*\" -exec grep -Hn \"mystring\" {} \\;<\/pre>\n<h2><span id=\"Remove_all_tmp_files\">Remove all *.tmp files<\/span><\/h2>\n<pre lang=\"bash\"> \r\nfind \/my\/path -name \"*.tmp\" -exec rm -rf {} \\;<\/pre>\n<h2><span id=\"Get_the_top_10_disk_use\">Get the top 10 disk use<\/span><\/h2>\n<pre lang=\"bash\">du -sh * | sort -h -r | head -10<\/pre>\n<h2><span id=\"Only_list_folders\">Only list folders<\/span><\/h2>\n<pre lang=\"bash\">ls -d -- *\/<\/pre>\n<h2><span id=\"Retrieve_bash_script_execution_directory_to_use_under_your_bash_script\">Retrieve bash script execution directory (to use under your bash script)<\/span><\/h2>\n<pre lang=\"bash\">DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"<\/pre>\n<h2><span id=\"Get_the_most_recent_element_in_the_current_directory\">Get the most recent element in the current directory<\/span><\/h2>\n<pre lang=\"bash\">ls -Art | tail -n 1<\/pre>\n<h2><span id=\"Copy_files_by_extension_recursively\">Copy files by extension recursively<\/span><\/h2>\n<pre lang=\"bash\">\r\nfind \/path\/to\/srcdir -name '*.txt' | cpio -pdm \/path\/to\/destdir\r\n# Note: we can use '-updm' for overwrite destination content.\r\n<\/pre>\n<h2><span id=\"Remove_files_older_than_5_days\">Remove files older than 5 days<\/span><\/h2>\n<pre lang=\"bash\">\r\nfind \/path\/to\/files* -type f -mtime +5 -exec rm {} \\;\r\n<\/pre>\n<p>You can also write :<\/p>\n<pre lang=\"bash\">\r\nfind \/path\/to\/files* -type f -mtime +5 -delete\r\n<\/pre>\n<h2><span id=\"find_all_files_that_does_not_have_777_permissions\">find all files that does not have 777 permissions<\/span><\/h2>\n<pre lang=\"bash\">\r\nfind \/path\/to\/files* -not -perm 0777\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 Partition1.1 Manage partition1.2 Extend partition2 Mount FileSystem2.1 Mount local disk2.2 Mount windows shared directory2.2.1 using smbfs2.2.2 using cifs2.3 Mount ssh directory2.3.1 Troubleshooting2.3.1.1 fuse: bad mount point `\/mnt\/mountpoint&#8217;: Transport endpoint is not connected2.4 Mount nfs2.5 Mount ftp2.6 Mount cdrom3 Commands3.1 Find a file containing a string3.2 Remove all *.tmp files3.3 Get the top 10 disk [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":443,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-943","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=943"}],"version-history":[{"count":24,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/943\/revisions"}],"predecessor-version":[{"id":1751,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/943\/revisions\/1751"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/443"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}