Linux shell

Mount as a local folder on ubuntu as webdav

Whats WebDav: Web Distributed Authoring and Versioning (WebDAV) is an extension of the Hypertext Transfer Protocol (HTTP) that facilitates collaboration between users in editing and managing documents and files stored on World Wide Web servers.
Whats [.net]: is cloud-storage service like Dropbox, SugarSync and google drive. After uploading your various documents, media files, and the like, you can easily access them online, share them with others, stream media to a mobile device, and so on. An awesome feature that comes with using on an android device is that you get 50GB of free space. Sadly per file size limit is a very low of 100MB 🙁 However you can enjoy as a local folder on your computer whether you use windows or linux. I just mounted it as a local folder on my Ubuntu 12.04 desktop and 11.10 Server and heres the simple steps to follow :

install davfs:

sudo apt-get install davfs2

make a directory where you will be mounting the box folder. I am using a folder called box under the home directory of a user called homer

mkdir /home/homer/box

mount the folder. after using this command just insert username/password when prompted.

sudo mount -t davfs /home/homer/box

add your credentials to /etc/davfs2/secrets

sudo nano /etc/davfs2/secrets

insert the following, just replace your username/pass in the proper spot.: username password”

now you also have access to dav:// as a location in your file explorer.

Linux shell

SSHFS mount remote file system locally over SSH

[et_pb_section admin_label=”Section” fullwidth=”on” specialty=”off”][et_pb_fullwidth_post_title admin_label=”Fullwidth Post Title” title=”on” meta=”on” author=”off” date=”on” categories=”on” comments=”off” featured_image=”on” featured_placement=”background” parallax_effect=”off” parallax_method=”on” text_orientation=”center” text_color=”dark” text_background=”on” text_bg_color=”rgba(255,255,255,0.9)” module_bg_color=”rgba(255,255,255,0)” title_all_caps=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_fullwidth_post_title][/et_pb_section][et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

SSHFS is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

So we have two systems remote.kpsn.pie and local.kpsn.pie. we want to mount directory /home/homer/supercooldir from remote.kpsn.pie as /home/user/remote in local.kpsn.pie and for this discussion on remote system your user is called homer. we will be doing all these commands as user on local system and not root.

This requires SSH key based authentication to be working between the machines prior to this being setup. check out other tutorial on this setup.

so first off you install sshfs on local.kpsn.pie

sudo apt-get install sshfs

Now you need to make the folder in where you will be mounting the remote folder so:

mkdir /home/user/remote

now we go about actually mounting the remote directory to the local one we made so:

sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote

What if you have a different port for ssh on remote? well simply use the -p flag, say the port is 12345:

sshfs -p 12345 -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote

to unmount you type:

fusermount -u /home/user/remote

to automagically mount this at startup edit /etc/rc.local

nano /etc/rc.local

and insert this line ABOVE the line saying exit 0

cd /home/user && su -c "/usr/bin/sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote" user

that last “user” is the local machine user. this allows the command to be run as the local machine user so the drive gets mounted properly.

this all is written for ubuntu but should work elsewhere. lemme know of any questions or concerns.

[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”bottom above footer” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

[/et_pb_text][et_pb_divider admin_label=”Divider” color=”#ffffff” show_divider=”off” divider_style=”solid” divider_position=”top” hide_on_mobile=”on”]

[/et_pb_divider][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]



Linux shell

Create Thumbnails from a bunch of images

Linux Code snippet. Ever wated to batch create thumbnails? “musclecarr” posted this bash script to create thumbnails of all images of a specific type. It uses imagemagick and specifically the convert command. minor modifications done to it and comments added for easy understanding, here it is :

# take argument or use current dir
# create dir thumbs if doesnt exist
[ -d "$DIR/thumbs" ] || mkdir "$DIR/thumbs"
# error out if cant enter dir for some reason (permissions?)
cd "$DIR" || { echo >&2 "error: couldn't enter directory: $DIR"; exit 1;}
# For every file with extension XXX (jpg in this case)
for i in ./*.jpg; do
# Resize image to 100x100
convert "$i" -resize 100x100 "$DIR/thumbs/$i"
# profit? nah.
Linux shell

recursively delete all empty subdirectories

find /home/user/somedir -depth -type d -empty -exec rmdir -v {} \;

This CAN and WILL destroy all your data and eat your small { dog | cat | turtle | parrot } if you aren’t careful! ALWAYS check the path twice and then check it again before using.

Linux shell

Directory FileCount

I have close to 3000 images in a folder and needed to know exactly how many for a stupid bet I made. I dont feel like counting them! there must be something in the linux world to make this easier…. well there is. simple extension of the ls command.

my directory is called images but I’m sure contains no images whatsoever. *cough* so lets get the basics :

ls -1 images | wc -l

what if you wanted to not count sub directories or symlinks?

find images -maxdepth 1 -type f | wc -l

want to add symlinks?

find images -maxdepth 1 -type f -follow | wc -l

so yeah the basics should be done 🙂